Hey everyone,
so I have a Game scene with world with a bunch of entities doing a bunch of physics interaction. Everything works fine. When my game logic is done, I clear everything with:
public void OnQuitClicked() { // ButtonCallback
var entityManager = World.DefaultGameObjectInjectionWorld.EntityManager;
entityManager.DestroyEntity(entityManager.UniversalQuery);
sceneManager.LoadScene("Menu"); // Async
}
When I relaunch the exact same Game scene, the very first frame (I assume) where a trigger is alive, I have get the following exception:
IndexOutOfRangeException: Index 144 is out of range of '6' Length.
Unity.Collections.NativeSlice`1[T].FailOutOfRangeError (System.Int32 index) (at /Users/builduser/buildslave/unity/build/Runtime/Export/NativeArray/NativeSlice.cs:222)
Unity.Collections.NativeSlice`1[T].CheckReadIndex (System.Int32 index) (at /Users/builduser/buildslave/unity/build/Runtime/Export/NativeArray/NativeSlice.cs:174)
Unity.Collections.NativeSlice`1[T].get_Item (System.Int32 index) (at /Users/builduser/buildslave/unity/build/Runtime/Export/NativeArray/NativeSlice.cs:199)
Unity.Physics.ITriggerEventJobExtensions+TriggerEventJobProcess`1[T].Execute (Unity.Physics.ITriggerEventJobExtensions+TriggerEventJobData`1[T]& jobData, System.IntPtr additionalData, System.IntPtr bufferRangePatchData, Unity.Jobs.LowLevel.Unsafe.JobRanges& ranges, System.Int32 jobIndex) (at Library/PackageCache/com.unity.physics@0.2.5-preview.1/Unity.Physics/Dynamics/Simulation/ITriggerEventsJob.cs:104)
It’s almost like a trigger event was lingering around from before when I nuked all Entities ![]()
Has anyone experienced this or found a workaround?
Note: My TriggerEventsJob is a [BurstCompile] struct MyTriggerJob : ITriggerEventsJob, but since my class isn’t even in the stacktrace, it shouldn’t matter I guess.
One possible source of the problem is that maybe my entityManager.DestroyEntity(entityManager.UniversalQuery); runs at a somewhat inopportune time (given that it’s from a button click, it should be on the main thread, right?) and the PhysicsWorld gets confused and then barfs up this exception once triggers are happening again?
Thanks in advance ![]()
(X-post for wider audience: https://forum.unity.com/threads/itriggereventsjob-crash-after-clearing-all-entities-and-recreating-the-world.837586/ )