Recast Graph and Multiple Scenes - Need for Filter API

Is there a way to tell a graph or the scan function to limit its scan to a single scene? I have multiple scenes in my game (which are mutually exclusive) and RecastGraph.Scan() is referencing game objects in the other scenes.

A CollectionSettings.Scene? property may work as an effective filter. The existing CollectionSettings.PhysicsScene? property may be shared across scenes.

I used to have two separate physics scenes – one for planetside gameplay and one for stellar gameplay. But by sharing a single physics scene and using layers to separate physics interactions, I gain approximately 0.7 MS CPU time per frame, which is significant.

But now A*Pathfinding is accessing colliders in other scenes which share similar tags.

Thanks,

Shaun

So these scenes do not overlap at all? None of the objects in one scene overlap another scene’s graph?

That’s right, no overlap. One is planetside and the other is in space. The ‘sharing’ of coordinate space is to achieve floating point precision. Both playable areas are centered about the origin.

If there aren’t any overlapping graphs would you be able to take advantage of scanning only the area in the graph you’re wanting to scan, with say, GraphUpdateScene?

The graphs do not overlap but the colliders contained across both scenes do overlap. That’s a problem I can’t seem to get around. Why not just add a scene filter?

Hi

If you, as you say, use the same physics scene but separate them by layers, then use the layer mask in the recast graph inspector. If you are going for any kind of performance, I would not recommend using the “Filter by tags” option, as it is significantly more performance intensive to look objects up by tag, rather than layer.

If instead your unity scenes use different physics scenes then you can set recastGraph.collectionSettings.physicsScene before the graph is scanned.

This field can only be set via code, as Unity does not persist them, or use unique IDs for them in any way.

So you can for example do something like:

var graph = AstarPath.active.data.graphs[0] as RecastGraph;
graph.collectionSettings.physicsScene = PhysicsSceneExtensions.GetPhysicsScene(myScene);
graph.Scan();

See CollectionSettings - A* Pathfinding Project

and Unity - Scripting API: PhysicsSceneExtensions.GetPhysicsScene

1 Like

Thanks, Aron!