InvalidOperationException: Structural changes are not allowed while iterating over entities. Please use EntityCommandBuffer instead.

maestroymn

New member
1762260323856.png
While switchin subtree on behavior tree during runtime, following exception is fired. I actually use this method to switch behavior in several other cases, but the exception only occurs on specific moment. Don't know what causes it. Any help or suggestion?

System.InvalidOperationException: Structural changes are not allowed while iterating over entities. Please use EntityCommandBuffer instead. at Unity.Entities.EntityDataAccess.CheckIsStructuralChange () [0x00018] in .\Library\PackageCache\com.unity.entities@1.3.10\Unity.Entities\EntityDataAccess.cs:336 at Unity.Entities.EntityDataAccess.BeforeStructuralChange () [0x00001] in .\Library\PackageCache\com.unity.entities@1.3.10\Unity.Entities\EntityDataAccess.cs:410 at Unity.Entities.EntityDataAccess.BeginStructuralChanges () [0x0000e] in .\Library\PackageCache\com.unity.entities@1.3.10\Unity.Entities\EntityDataAccess.cs:420 at Unity.Entities.EntityManager.RemoveComponent (Unity.Entities.Entity entity, Unity.Entities.ComponentType componentType) [0x00008] in .\Library\PackageCache\com.unity.entities@1.3.10\Unity.Entities\EntityManager.cs:2178 at Unity.Entities.EntityManager.RemoveComponent[T] (Unity.Entities.Entity entity) [0x00001] in .\Library\PackageCache\com.unity.entities@1.3.10\Unity.Entities\EntityManager.cs:2340 at Opsive.BehaviorDesigner.Runtime.BehaviorTree.ClearTree (Unity.Entities.World world, Unity.Entities.Entity entity) [0x00023] in .\Packages\com.opsive.behaviordesigner\Runtime\BehaviorTree.cs:1234 at Opsive.BehaviorDesigner.Runtime.BehaviorTree.ClearTree () [0x00018] in .\Packages\com.opsive.behaviordesigner\Runtime\BehaviorTree.cs:1218 at Opsive.BehaviorDesigner.Runtime.BehaviorTree.set_Subgraph (Opsive.GraphDesigner.Runtime.IGraph value) [0x00019] in .\Packages\com.opsive.behaviordesigner\Runtime\BehaviorTree.cs:79 at Parodie.Runtime.GamePlay.CharacterCommon.Controllers.CharacterBehaviorTreeController.SwitchToBehavior (Opsive.BehaviorDesigner.Runtime.Subtree source) [0x0004f] in C:\Users\Pc\Documents\UnityProjects\scalpers_spoils_main\Assets\Parodie\Runtime\GamePlay\CharacterCommon\Controllers\CharacterBehaviorTreeController.cs:58 at Parodie.Runtime.GamePlay.DropEvent.Npc.DropEventNpcController.StartLooting () [0x00001] in C:\Users\Pc\Documents\UnityProjects\scalpers_spoils_main\Assets\Parodie\Runtime\GamePlay\DropEvent\Npc\DropEventNpcController.cs:61 at Parodie.Runtime.GamePlay.DropEvent.Npc.Behaviors.Looter.ReturnLooting.OnStart () [0x0002e] in C:\Users\Pc\Documents\UnityProjects\scalpers_spoils_main\Assets\Parodie\Runtime\GamePlay\DropEvent\Npc\Behaviors\Looter\ReturnLooting.cs:14 at Opsive.BehaviorDesigner.Runtime.Tasks.StackedTask.OnUpdate () [0x00059] in .\Packages\com.opsive.behaviordesigner\Runtime\Tasks\StackedTask.cs:235 at Opsive.BehaviorDesigner.Runtime.Systems.TaskObjectSystem.OnUpdate (Unity.Entities.SystemState& state) [0x00235] in .\Packages\com.opsive.behaviordesigner\Runtime\Systems\TaskObjectSystem.cs:100 at Opsive.BehaviorDesigner.Runtime.Systems.TaskObjectSystem.__codegen__OnUpdate (System.IntPtr self, System.IntPtr state) [0x00012] in <680ec47e3bdb40548f43f99bbf2c5b36>:0 at Unity.Entities.SystemBaseRegistry+<>c__DisplayClass9_0.<SelectBurstFn>b__0 (System.IntPtr system, System.IntPtr state) [0x00002] in .\Library\PackageCache\com.unity.entities@1.3.10\Unity.Entities\SystemBaseRegistry.cs:249
 
Adding a slight delay to switchBehavior method call fixes the issue on specific moment. But of course I would like to know the source of the issue, in order to come up with better solution for stability.
 
It looks like you created a new task? You should instead use the Set Subtree task.
 
I didn't know there was a setSubtree task, I tested it and no issue occurs. However, is there a way to enable that newly set behavior? Other than leaving "Start When Enabled" checkbox marked on BehaviorTree component?
 
You can use the Task Delegate to call StartBehavior, but I can also add it as an option to the task.
 
Well, I edited the Subtree task for now :P But I believe that will be a cool feature to manage subtree's while setting them through the tree
 
Back
Top