Skip to content

Game.Pathfind.CoverageResult

Assembly: Assembly-CSharp
Namespace: Game.Pathfind

Type: struct

Base: System.ValueType

Summary:
A small, blittable data container used by the pathfinding/coverage system to record a target entity and a two-component cost associated with that target. Designed for use in low-allocation contexts (NativeArrays, jobs, etc.). The struct has no behavior — it only carries data: an Entity reference and a float2 cost vector that typically represents two cost metrics (for example primary and secondary costs, or distance and penalty). Default initialization yields Entity.Null and float2.zero.


Fields

  • public Unity.Entities.Entity m_Target
    This is the Entity that the coverage/pathfinding result refers to. The value may be Entity.Null when no valid target is present. When storing or using this value make sure the Entity is valid in the expected World/EntityManager.

  • public Unity.Mathematics.float2 m_TargetCost
    A two-component cost value associated with the target. Semantics are project-specific, but commonly used as (primaryCost, secondaryCost) or (distance, penalty). Being a float2 makes this compact and suitable for math operations in jobs.

Properties

  • This struct exposes no properties; it only contains public fields.

Constructors

  • public CoverageResult()
    The default (parameterless) constructor provided by C# for value types. It initializes m_Target to Entity.Null (default Entity) and m_TargetCost to float2.zero.

You can also create an explicit constructor in your code if you prefer:

public CoverageResult(Entity target, float2 cost)
{
    m_Target = target;
    m_TargetCost = cost;
}

Methods

  • This struct defines no methods.

Usage Example

using Unity.Entities;
using Unity.Mathematics;
using Unity.Collections;

// create a single result
var result = new Game.Pathfind.CoverageResult
{
    m_Target = someEntity,
    m_TargetCost = new float2(12.5f, 1.0f) // primary and secondary cost
};

// store results in a NativeArray for processing in a job
var results = new NativeArray<Game.Pathfind.CoverageResult>(capacity, Allocator.TempJob);
results[0] = result;

// sample usage in a job (pseudo)
public struct ProcessCoverageJob : Unity.Jobs.IJobParallelFor
{
    public NativeArray<Game.Pathfind.CoverageResult> results;

    public void Execute(int index)
    {
        var r = results[index];
        // read r.m_Target and r.m_TargetCost here
    }
}

Notes: - Because this type is blittable and small, it's efficient to use in NativeContainers and multi-threaded jobs. - Ensure Entities referenced by m_Target remain valid for the lifetime of the structure or are validated before use.