Game.Common.RaycastResult
Assembly:
Assembly-CSharp (game's main runtime assembly; may vary by build)
Namespace:
Game.Common
Type:
struct
Base:
Colossal.Collections.IAccumulable
Summary:
Represents the result of a raycast operation in the game. Contains the hit information (distance, hit entity, etc.) and the owning entity that issued/owns the raycast result. Implements IAccumulable so multiple RaycastResult values can be combined (reduced) deterministically — e.g., to pick the nearest hit or apply a tie-breaker based on entity index when distances are equal. This struct is intended for use in parallel or aggregated raycasting scenarios (jobs, accumulators, collection reductions).
Fields
-
public RaycastHit m_Hit
Contains the raw hit information for this raycast result. Key fields used by Accumulate include m_NormalizedDistance (distance along the ray, normalized) and m_HitEntity (the entity hit, whose Index is used as a tie-breaker). The exact shape of RaycastHit is defined elsewhere in the codebase. -
public Entity m_Owner
The Entity that owns or produced this raycast result. Used to determine whether this result is valid (Entity.Null indicates "no owner" / empty result). Unity.Entities.Entity is used here; Entity.Null represents no owner.
Properties
- None (this struct exposes only public fields and the Accumulate method)
Constructors
- Implicit default constructor (public RaycastResult())
Structs in C# have an implicit parameterless constructor that zero-initializes fields. Typical usage initializes m_Owner to Entity.Null and m_Hit to default before being populated by a raycast routine.
Methods
public void Accumulate(RaycastResult other)
Merges another RaycastResult into this one following these rules:- If this.m_Owner is Entity.Null, replace this result with other.
- Otherwise, if other.m_Owner is not Entity.Null and other.m_Hit.m_NormalizedDistance is less than this.m_Hit.m_NormalizedDistance, replace this with other (choose the nearer hit).
- If distances are equal, use a deterministic tie-breaker: replace if other.m_Hit.m_HitEntity.Index < this.m_Hit.m_HitEntity.Index.
- Implementation detail: the method uses
this = other;
to copy the other struct into this one.
Remarks:
- Designed for deterministic reduction in parallel contexts (e.g., accumulated raycast results from multiple threads/jobs).
- Relies on Entity.Null and RaycastHit internals; ensure those types are consistent when using in custom code.
- Because this is a struct method that assigns to this
, be careful when calling on temporary values — typical use is on a local variable or accumulator slot.
Usage Example
// Basic manual usage
var a = new RaycastResult(); // default: m_Owner == Entity.Null
var b = new RaycastResult
{
m_Owner = someEntity,
m_Hit = someHit // assume someHit.m_NormalizedDistance and m_HitEntity are set
};
a.Accumulate(b); // a becomes b because a had no owner
// Combining two results and keeping the nearest (or using the tie-breaker)
var result = new RaycastResult();
result.Accumulate(raycastResultFromSource1);
result.Accumulate(raycastResultFromSource2);
// result now holds the chosen (nearest / tie-broken) hit
// Typical pattern in a job or accumulation routine:
// - initialize per-thread accumulator to default (Owner = Entity.Null)
// - for each raycast hit found, produce a RaycastResult and call Accumulate on the accumulator
// - once all hits processed, the accumulator contains the final chosen hit
{{ This struct is a lightweight, deterministic accumulator for raycast outcomes. Use it when you need to merge multiple raycast results (for example, from spatial partitions, multiple colliders, or parallel jobs) and want a consistent rule to pick the "best" hit: nearest first, then lowest entity index as a tie-breaker. }}