Hi!
I am trying to define a high penalty zone on my navmesh by scripting, using GraphUpdateObject.
In a script applied to my plane, in Awake() my code is:
`
// …compute the Bounds position and size…
bb = new Bounds(new Vector3(proj.transform.position.x, 0, proj.transform.position.z), new Vector3(maxX - minX, 2, maxZ - minZ));
guo = new GraphUpdateObject(bb);
guo.addPenalty = 10000;
AstarPath.active.UpdateGraphs(guo);
`
This results in the folllowing exception:
`
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.
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 E:\Users\Piero\Documents\TesiOfficial\Assets\AstarPathfindingProject\Generators\Utilities\Voxels\VoxelRegion.cs:1004
at Pathfinding.Voxels.Voxelize.BuildRegions () [0x00276] in E:\Users\Piero\Documents\TesiOfficial\Assets\AstarPathfindingProject\Generators\Utilities\Voxels\VoxelRegion.cs:919
at Pathfinding.RecastGraph.BuildTileMesh (Pathfinding.Voxels.Voxelize vox, Int32 x, Int32 z) [0x001d5] in E:\Users\Piero\Documents\TesiOfficial\Assets\AstarPathfindingProject\Generators\RecastGenerator.cs:1417
at Pathfinding.RecastGraph.UpdateArea (Pathfinding.GraphUpdateObject guo) [0x0025e] in E:\Users\Piero\Documents\TesiOfficial\Assets\AstarPathfindingProject\Generators\RecastGenerator.cs:902
at AstarPath.ProcessGraphUpdatesAsync (System.Object _astar) [0x00074] in E:\Users\Piero\Documents\TesiOfficial\Assets\AstarPathfindingProject\Core\AstarPath.cs:1135
`
I did some reaserch on the forum and I found this post so I followed Aron’s advice.
But this led me to another exception:
Error while updating graphs System.InvalidOperationException: No Voxelizer object. UpdateAreaInit should have been called before this function. at Pathfinding.RecastGraph.UpdateArea (Pathfinding.GraphUpdateObject guo) [0x001da] in E:\\Users\\Piero\\Documents\\TesiOfficial\\Assets\\AstarPathfindingProject\\Generators\\RecastGenerator.cs:869 at AstarPath.ProcessGraphUpdates (Boolean force) [0x001b9] in E:\\Users\\Piero\\Documents\\TesiOfficial\\Assets\\AstarPathfindingProject\\Core\\AstarPath.cs:1073 UnityEngine.Debug:LogError(Object) AstarPath:ProcessGraphUpdates(Boolean) (at Assets/AstarPathfindingProject/Core/AstarPath.cs:1075) AstarPath:ProcessWorkItems(Boolean) (at Assets/AstarPathfindingProject/Core/AstarPath.cs:808) AstarPath:PerformBlockingActions(Boolean, Boolean) (at Assets/AstarPathfindingProject/Core/AstarPath.cs:714) AstarPath:Update() (at Assets/AstarPathfindingProject/Core/AstarPath.cs:671)
I think that this is related to the fact that with the hack adviced in the post, UpdateAreaInit() is never called (lines 1030/1067 of AStarPath.cs).
Do I have to call UpdateAreaInit() by myself (maybe directly in AStarPath.cs, along with the change suggested on the previous post), or I have to do something different?