For the context, I’m using a recast graph on my scene. Since some areas are separated by gaps or are not on the same level, I’m using node links to connect them.
From what I understand when you add some NodeLink it generates a Point Graph automatically. I’m using NodeLink2 which is the only one that kind of work on my map.
So far so good. The seekers are able to find paths passing through my links and everything looks fine.
I’m using NavMeshCut and the TileHandlerHelper to block at runtime some parts of the graphs and unlock them afterwards. This is also working great. The TileHandlerHelper refreshTime is set to -1 since I’m manually calling the refresh.
Now I’d like to disable some links at runtime (i.e. disable some node in the PointGraph) but I’m unable to do so.
This is what I tried …
`
public void SetGraphWalkability (bool walkable)
{
// Set navcutter
navCutter.enabled = !walkable;
// activate refresh mode
navCutter.ForceUpdate ();
// use tileHandlerHelper to refresh the graph
MissionManager.Instance.AStarHandler.ForceUpdate ();
// Set GraphUpdateObject (for point graph)
graphUpdateObject.setWalkability = walkable;
// Update graph using this GraphUpdateObject
AstarPath.active.UpdateGraphs(graphUpdateObject);
}
`
… and it unfortunatly raises an exception
Exception while updating graphs:
System.ArgumentException: CompareBaseObjectsInternal can only be called from the main thread.
Constructors and field initializers will be executed from the loading thread when loading a scene.
Don’t use this function in the constructor or field initializers, instead move initialization code to the Awake or Start function.
I could be misunderstanding some part of the system so any help/explanations would be great.
Thanks in advance for the help.
Of course! I should have done it in the first place. Here is the log
Exception while updating graphs:
System.ArgumentException: CompareBaseObjectsInternal can only be called from the main thread.
Constructors and field initializers will be executed from the loading thread when loading a scene.
Don’t use this function in the constructor or field initializers, instead move initialization code to the Awake or Start function.
at (wrapper managed-to-native) UnityEngine.Object:CompareBaseObjectsInternal (UnityEngine.Object,UnityEngine.Object)
at UnityEngine.Object.CompareBaseObjects (UnityEngine.Object lhs, UnityEngine.Object rhs) [0x00000] in C:\BuildAgent\work\d3d49558e4d408f4\artifacts\EditorGenerated\UnityEngineObject.cs:48
at UnityEngine.Object.op_Inequality (UnityEngine.Object x, UnityEngine.Object y) [0x00000] in C:\BuildAgent\work\d3d49558e4d408f4\artifacts\EditorGenerated\UnityEngineObject.cs:162
at Pathfinding.Voxels.Voxelize.FilterSmallRegions (System.UInt16[] reg, Int32 minRegionSize, Int32 maxRegions) [0x00006] in P:\project\dev\Assets\AstarPathfindingProject\Generators\Utilities\Voxels\VoxelRegion.cs:1004
at Pathfinding.Voxels.Voxelize.BuildRegions () [0x00276] in P:\project\dev\Assets\AstarPathfindingProject\Generators\Utilities\Voxels\VoxelRegion.cs:919
at Pathfinding.RecastGraph.BuildTileMesh (Pathfinding.Voxels.Voxelize vox, Int32 x, Int32 z) [0x00315] in P:\project\dev\Assets\AstarPathfindingProject\Generators\RecastGenerator.cs:1369
at Pathfinding.RecastGraph.UpdateArea (Pathfinding.GraphUpdateObject guo) [0x0025e] in P:\project\dev\Assets\AstarPathfindingProject\Generators\RecastGenerator.cs:865
at AstarPath.ProcessGraphUpdatesAsync (System.Object _astar) [0x00074] in P:\project\dev\Assets\AstarPathfindingProject\Core\AstarPath.cs:1139
Ah, I see.
The graph update is done on a separate thread, however that thread looks for the RecastMeshObj component, and Unity doesn’t like that you use components in a separate thread. To solve this, you can open up the RecastGenerator.cs script, find the method CanUpdateAsync and change the return value of that method to be just GraphUpdateThreading.UnityThread.