reckfellENGINE

AStar2D

Path search on an explicit graph of 2D points with directed edges and entry weights.

On this page
class AStar2DReckfellSharpInherits RefCounted

Create a graph, add points with AddPoint, connect them using ConnectPoints, and query GetIdPath or GetPointPath. These are route data: the engine creates no collision clearance, moves no character and does not automatically update graph positions from Entities. Dispose the owned instance.

ArePointsConnected accepts either direction by default; use false for a directed query. A partial path may not reach the goal: check its last ID. A disabled start produces no path even with partial enabled.

Transition cost is _ComputeCost(fromId, toId) × destination weightScale. Optimal search requires an admissible consistent heuristic. For arbitrary nonnegative costs, overriding _EstimateCost to return 0 is a clear starting strategy. Native defaults use Euclidean distance; calling C# base virtual methods does not retrieve that formula.

Small graphs, directed edges, weights, disabled points, partial paths, closest queries and C# callbacks were tested in Windows headless. Large graphs, concurrent search, physical clearance and other platforms were not accepted.

Declarations checked against C# SDK 1.0.0. Expand a name to see declarations and documentation.

Constructors1

AStar2DConstructor
# AStar2D
C#
public AStar2D();

Creates an empty owned graph, not a level Entity or navigation mesh. Add points and edges explicitly. Dispose the instance when no longer needed.

Properties1

NeighborFilterEnabledProperty
# NeighborFilterEnabled
C#
public bool NeighborFilterEnabled { get; set; }

Enables _FilterNeighbor calls while expanding neighbors; false by default. An override returning true rejects that transition. Does not alter GetPointConnections, ArePointsConnected or geometric closest queries.

Methods30

AddPointvoid
# AddPoint
C#
public void AddPoint(long id, Vector2 position, float weightScale = 1f);

Adds a nonnegative ID at a finite position. weightScale is a finite nonnegative multiplier for entering this point, default 1. Reusing an ID updates position/weight while retaining edges and disabled state. Adds no edges by itself. Invalid IDs/negative weights produce native diagnostics; validate NaN/Infinity before calling.

Parameters
NameTypeDefault
idlong—
positionVector2—
weightScalefloat1f
id

Existing nonnegative ID; AddPoint also accepts a new ID. Not an array index.

position

Finite position in your chosen graph coordinate system.

weightScale

Finite entry-cost multiplier ≥0. Check the heuristic for weights <1.

ArePointsConnectedbool
# ArePointsConnected
C#
public bool ArePointsConnected(long id, long toId, bool bidirectional = true);

Checks a direct edge rather than route reachability. Crucially, bidirectional=true accepts an edge in EITHER direction; it does not require two edges. false tests only id→toId. To require two-way connectivity, query both directions with false. Disabled state and neighbor filtering do not change this query.

Parameters
NameTypeDefault
idlong—
toIdlong—
bidirectionalbooltrue
id

Existing nonnegative ID; AddPoint also accepts a new ID. Not an array index.

toId

Another existing point ID; for path queries, the goal may be unreachable.

bidirectional

For ArePointsConnected, true accepts either direction; for ConnectPoints/DisconnectPoints it acts on both. false always means id→toId.

Returns bool

Whether a direct edge satisfies the selected direction rule, not route reachability.

Clearvoid
# Clear
C#
public void Clear();

Removes all points and edges and resets the available-ID candidate to 0. Existing C# result arrays remain snapshots. Does not promise to release all reserved memory.

ConnectPointsvoid
# ConnectPoints
C#
public void ConnectPoints(long id, long toId, bool bidirectional = true);

Connects two existing distinct points: both directions by default, or only id→toId with false. Reconnecting does not duplicate a neighbor. Checks no collision/geometry clearance and moves no character.

Parameters
NameTypeDefault
idlong—
toIdlong—
bidirectionalbooltrue
id

Existing nonnegative ID; AddPoint also accepts a new ID. Not an array index.

toId

Another existing point ID; for path queries, the goal may be unreachable.

bidirectional

For ArePointsConnected, true accepts either direction; for ConnectPoints/DisconnectPoints it acts on both. false always means id→toId.

DisconnectPointsvoid
# DisconnectPoints
C#
public void DisconnectPoints(long id, long toId, bool bidirectional = true);

Removes an edge between existing points. true removes both directions; false removes only id→toId, retaining the reverse edge if present. Points remain. Does not create a missing edge.

Parameters
NameTypeDefault
idlong—
toIdlong—
bidirectionalbooltrue
id

Existing nonnegative ID; AddPoint also accepts a new ID. Not an array index.

toId

Another existing point ID; for path queries, the goal may be unreachable.

bidirectional

For ArePointsConnected, true accepts either direction; for ConnectPoints/DisconnectPoints it acts on both. false always means id→toId.

GetAvailablePointIdlong
# GetAvailablePointId
C#
public long GetAvailablePointId();

Returns the current available nonnegative candidate. Does not reserve it: repeated calls without AddPoint can return the same value. Removed IDs can be reused; this is neither a global UUID nor a promise of the smallest free ID.

Returns long

Available candidate ID without reservation.

GetClosestPointlong
# GetClosestPoint
C#
public long GetClosestPoint(Vector2 toPosition, bool includeDisabled = false);

Finds the geometrically closest point, breaking equal-distance ties by smaller ID. Excludes disabled points by default. Does not test routes, edges or neighbor filtering. Source initializes squared-distance threshold to 1e20: extreme coordinates require separate validation.

Parameters
NameTypeDefault
toPositionVector2—
includeDisabledboolfalse
toPosition

Finite geometric-query position in the same coordinate system as graph points.

includeDisabled

true includes disabled candidates in the closest-point query; false by default.

Returns long

Geometrically nearest eligible candidate ID, or −1 if none was found.

GetClosestPositionInSegmentVector2
# GetClosestPositionInSegment
C#
public Vector2 GetClosestPositionInSegment(Vector2 toPosition);

Projects onto the closest existing segment with both endpoints enabled. This is geometric: edge direction and neighbor filtering do not determine the projection. Returns Vector2.Zero when no eligible segment exists; zero is also a valid position, not a reliable failure marker. Do not depend on segment order for distance ties.

Parameters
NameTypeDefault
toPositionVector2—
toPosition

Finite geometric-query position in the same coordinate system as graph points.

Returns Vector2

Projected position; Vector2.Zero is also used when no segment was found.

GetIdPath2 overloads
# GetIdPath · 1/2
C#
public long[] GetIdPath(long fromId, long toId);

Returns route IDs including fromId and toId. Both IDs must exist. No reachable route yields an empty array; enabled fromId==toId yields one ID, while a disabled start yields empty even with partial enabled. allowPartialPath=true permits a path to the best reached candidate by heuristic then travel cost; its endpoint may differ from toId. A disabled goal is not visited. Check the last ID before declaring arrival. Do not run concurrent searches/mutations on one instance.

Parameters
NameTypeDefault
fromIdlong—
toIdlong—
fromId

Existing path-start ID or callback source-point ID.

toId

Another existing point ID; for path queries, the goal may be unreachable.

Returns long[]

New long[] ordered from start to end; empty without a result, and a partial endpoint may not be the goal.

# GetIdPath · 2/2
C#
public long[] GetIdPath(long fromId, long toId, bool allowPartialPath = false);

Returns route IDs including fromId and toId. Both IDs must exist. No reachable route yields an empty array; enabled fromId==toId yields one ID, while a disabled start yields empty even with partial enabled. allowPartialPath=true permits a path to the best reached candidate by heuristic then travel cost; its endpoint may differ from toId. A disabled goal is not visited. Check the last ID before declaring arrival. Do not run concurrent searches/mutations on one instance.

Parameters
NameTypeDefault
fromIdlong—
toIdlong—
allowPartialPathboolfalse
fromId

Existing path-start ID or callback source-point ID.

toId

Another existing point ID; for path queries, the goal may be unreachable.

allowPartialPath

true permits ending at a reached candidate when the goal is inaccessible. Does not guarantee reaching toId or allow a disabled start.

Returns long[]

New long[] ordered from start to end; empty without a result, and a partial endpoint may not be the goal.

GetPointCapacitylong
# GetPointCapacity
C#
public long GetPointCapacity();

Returns internal point-storage capacity, not the number of points or a path-length limit. Use GetPointCount for the count.

Returns long

Current internal-storage capacity rather than count.

GetPointConnectionslong[]
# GetPointConnections
C#
public long[] GetPointConnections(long id);

Returns outgoing neighbor IDs for an existing point. The other end of a one-way edge can have an empty list. Includes disabled/filtered neighbors: this describes graph structure rather than eligible transitions in the current search. Do not assume sorted order.

Parameters
NameTypeDefault
idlong—
id

Existing nonnegative ID; AddPoint also accepts a new ID. Not an array index.

Returns long[]

New long[] of outgoing IDs with no sorting promise.

GetPointCountlong
# GetPointCount
C#
public long GetPointCount();

Returns the number of existing points, including disabled ones. Not the edge count or capacity.

Returns long

Number of existing points, including disabled ones.

GetPointIdslong[]
# GetPointIds
C#
public long[] GetPointIds();

Returns a snapshot of all IDs, including disabled points. IDs can be sparse and exceed int.MaxValue; do not use them as point-array indices without your own mapping. Order is not guaranteed to be sorted.

Returns long[]

New long[] containing every ID, with no sorting promise.

GetPointPath2 overloads
# GetPointPath · 1/2
C#
public Vector2[] GetPointPath(long fromId, long toId);

Returns path-point positions in the coordinate system supplied to AddPoint. Complete/partial-path rules match GetIdPath; this is neither a smoothed trajectory nor collision clearance. Use the ID path to verify arrival for a partial query. Mutating the returned C# array does not edit the graph. Do not query one instance concurrently.

Parameters
NameTypeDefault
fromIdlong—
toIdlong—
fromId

Existing path-start ID or callback source-point ID.

toId

Another existing point ID; for path queries, the goal may be unreachable.

Returns Vector2[]

New Vector2[] ordered from start to end; empty without a result.

# GetPointPath · 2/2
C#
public Vector2[] GetPointPath(long fromId, long toId, bool allowPartialPath = false);

Returns path-point positions in the coordinate system supplied to AddPoint. Complete/partial-path rules match GetIdPath; this is neither a smoothed trajectory nor collision clearance. Use the ID path to verify arrival for a partial query. Mutating the returned C# array does not edit the graph. Do not query one instance concurrently.

Parameters
NameTypeDefault
fromIdlong—
toIdlong—
allowPartialPathboolfalse
fromId

Existing path-start ID or callback source-point ID.

toId

Another existing point ID; for path queries, the goal may be unreachable.

allowPartialPath

true permits ending at a reached candidate when the goal is inaccessible. Does not guarantee reaching toId or allow a disabled start.

Returns Vector2[]

New Vector2[] ordered from start to end; empty without a result.

GetPointPositionVector2
# GetPointPosition
C#
public Vector2 GetPointPosition(long id);

Reads the stored position of an existing ID. Graph positions do not automatically track Entity2D. A missing ID produces diagnostics and a zero fallback, so check HasPoint first.

Parameters
NameTypeDefault
idlong—
id

Existing nonnegative ID; AddPoint also accepts a new ID. Not an array index.

Returns Vector2

Stored Vector2; diagnosed zero fallback for an invalid ID.

GetPointWeightScalefloat
# GetPointWeightScale
C#
public float GetPointWeightScale(long id);

Reads the entry-cost multiplier of an existing point. Not an individual edge cost or heuristic. For an invalid ID, a diagnosed zero fallback must not be treated as a valid weight.

Parameters
NameTypeDefault
idlong—
id

Existing nonnegative ID; AddPoint also accepts a new ID. Not an array index.

Returns float

Entry multiplier; diagnosed zero fallback for an invalid ID.

HasPointbool
# HasPoint
C#
public bool HasPoint(long id);

Tests ID existence independently of disabled state and edges. Use before queries requiring an existing point.

Parameters
NameTypeDefault
idlong—
id

Existing nonnegative ID; AddPoint also accepts a new ID. Not an array index.

Returns bool

true if the ID exists, including disabled points.

IsNeighborFilterEnabledbool
# IsNeighborFilterEnabled
C#
public bool IsNeighborFilterEnabled();

Reads whether searches invoke _FilterNeighbor. The flag neither guarantees an override exists nor changes stored edges.

Returns bool

Current NeighborFilterEnabled value.

IsPointDisabledbool
# IsPointDisabled
C#
public bool IsPointDisabled(long id);

Reads the disabled state of an existing point. A disabled start cannot begin a search; disabled neighbors are skipped. Not an ID-existence test.

Parameters
NameTypeDefault
idlong—
id

Existing nonnegative ID; AddPoint also accepts a new ID. Not an array index.

Returns bool

Disabled flag of an existing point; an invalid ID is not an ordinary result.

RemovePointvoid
# RemovePoint
C#
public void RemovePoint(long id);

Removes an existing ID and its incoming and outgoing edges. Disabling instead retains graph structure. The removed ID can become the next GetAvailablePointId candidate.

Parameters
NameTypeDefault
idlong—
id

Existing nonnegative ID; AddPoint also accepts a new ID. Not an array index.

ReserveSpacevoid
# ReserveSpace
C#
public void ReserveSpace(long numNodes);

Reserves storage for a positive point count without creating points. An allocation setting, not grid generation or a maximum-ID limit. Zero/negative values produce diagnostics; do not use it as a shrink command.

Parameters
NameTypeDefault
numNodeslong—
numNodes

Positive desired point-storage capacity, not a count of Entities to create.

SetNeighborFilterEnabledvoid
# SetNeighborFilterEnabled
C#
public void SetNeighborFilterEnabled(bool enabled);

Sets the same flag as NeighborFilterEnabled. Enable it to invoke _FilterNeighbor; an override alone is insufficient.

Parameters
NameTypeDefault
enabledbool—
enabled

Enables/disables search-filter calls, not graph points themselves.

SetPointDisabledvoid
# SetPointDisabled
C#
public void SetPointDisabled(long id, bool disabled = true);

Disables an existing point by default; false enables it again. The point and edges remain. Disabling neither removes the ID nor tests its existence.

Parameters
NameTypeDefault
idlong—
disabledbooltrue
id

Existing nonnegative ID; AddPoint also accepts a new ID. Not an array index.

disabled

true disables the point; false restores it to searches.

SetPointPositionvoid
# SetPointPosition
C#
public void SetPointPosition(long id, Vector2 position);

Changes an existing point position for subsequent queries and default costs. Edges remain; previously returned path arrays do not update. Supply finite coordinates in one consistent coordinate system.

Parameters
NameTypeDefault
idlong—
positionVector2—
id

Existing nonnegative ID; AddPoint also accepts a new ID. Not an array index.

position

Finite position in your chosen graph coordinate system.

SetPointWeightScalevoid
# SetPointWeightScale
C#
public void SetPointWeightScale(long id, float weightScale);

Changes the finite nonnegative entry-cost multiplier. It multiplies _ComputeCost even for C# overrides; the start has no separate entry charge. Values below 1 can make the default Euclidean heuristic overestimate: configure an admissible consistent heuristic, such as 0 with nonnegative costs, for reliable search.

Parameters
NameTypeDefault
idlong—
weightScalefloat—
id

Existing nonnegative ID; AddPoint also accepts a new ID. Not an array index.

weightScale

Finite entry-cost multiplier ≥0. Check the heuristic for weights <1.

_ComputeCostfloat
# _ComputeCost
C#
public virtual float _ComputeCost(long fromId, long toId);

Overridable base cost for a directed transition between connected points. The engine additionally multiplies it by the destination weightScale. Native behavior without an override is Euclidean distance. C# base._ComputeCost returns default(float), not the native formula: explicitly compute GetPointPosition(fromId).DistanceTo(GetPointPosition(toId)) for distance. Return a finite nonnegative cost.

Parameters
NameTypeDefault
fromIdlong—
toIdlong—
fromId

Existing path-start ID or callback source-point ID.

toId

Another existing point ID; for path queries, the goal may be unreachable.

Returns float

Finite nonnegative base cost; the engine still applies destination weight.

_EstimateCostfloat
# _EstimateCost
C#
public virtual float _EstimateCost(long fromId, long endId);

Overridable remaining-cost heuristic, not a charged transition cost. Native search without an override uses Euclidean distance. Optimal routes require an admissible consistent estimate; closed points are not reopened. With nonnegative costs, return 0 avoids overestimation but can expand the search. C# base._EstimateCost itself returns default(float), not native distance.

Parameters
NameTypeDefault
fromIdlong—
endIdlong—
fromId

Existing path-start ID or callback source-point ID.

endId

Existing goal ID used to estimate remaining cost.

Returns float

Finite consistent lower-bound estimate of remaining cost.

_FilterNeighborbool
# _FilterNeighbor
C#
public virtual bool _FilterNeighbor(long fromId, long neighborId);

Override to reject fromId→neighborId: true skips the neighbor, false permits ordinary processing. Called only with NeighborFilterEnabled=true. Do not mutate the graph from the callback or mistake true for permission. A search filter, not a physics collision test.

Parameters
NameTypeDefault
fromIdlong—
neighborIdlong—
fromId

Existing path-start ID or callback source-point ID.

neighborId

Existing ID of the outgoing neighbor being considered.

Returns bool

true rejects this transition; false does not filter it.

Reckfell Engine documentationBack to top ↑
QUICK LINKSGetting startedEntity hierarchyC# & .NET 10Scenes and prefabs
Reckfell guides and full API K
reckfellENGINE
RECKFELL ACCOUNT

Sign in

Sign in to your Reckfell account.

One account for the entire Reckfell platform.