Raycast / Hit Cache

GetRaycastHits

public IEnumerable<Vector3> GetRaycastHits() => m_HitCache.ConvertAll(h => h.point);

Purpose: Get all hit points (world space) from the last rebuild. Returns: IEnumerable<Vector3> Notes: Handy for debug rendering or custom analytics.


GetHitTransforms

public List<Transform> GetHitTransforms()
{
    List<Transform> list = new();
    foreach (var h in m_HitCache)
        if (h.transform && !list.Contains(h.transform))
            list.Add(h.transform);
    return list;
}

Purpose: Unique set of Transforms that were hit. Returns: List<Transform> Notes: Which objects were touched by the projection.


GetHitMaterialSet

public HashSet<Material> GetHitMaterialSet()
{
    HashSet<Material> set = new();
    foreach (var h in m_HitCache)
        if (h.collider && h.collider.TryGetComponent(out Renderer r) && r.sharedMaterials != null)
            foreach (var mat in r.sharedMaterials)
                if (mat) set.Add(mat);
    return set;
}

Purpose: Unique set of Materials belonging to hit renderers. Returns: HashSet<Material> Notes: Useful for material-specific logic or reporting.


GetLayerHitStatistics

Purpose: Map Layer → hit count. Returns: Dictionary<int,int> Notes: Helps tune masks and performance per-layer.


ClearHitCache

Purpose: Clear cached hits (does not rebuild). Returns: void


RegisterOnHitCallback

Purpose: Register a filter + callback to be invoked for each cached hit after a rebuild. Parameters:

  • filter — predicate; only hits returning true trigger the callback.

  • callback — invoked for each passing hit. Returns: void Notes: You can register multiple filtered callbacks; great for analytics and selective processing.


Last updated