Search Unity

Question Loading Scene Causing Crash

Discussion in 'Physics for ECS' started by thebigguboggu, Oct 17, 2022.

  1. thebigguboggu

    thebigguboggu

    Joined:
    Mar 8, 2020
    Posts:
    4
    Hey, I'm having some trouble loading a new level, here's the code:
    Code (CSharp):
    1. EntityManager manager = World.DefaultGameObjectInjectionWorld.EntityManager;
    2. manager.DestroyEntity(manager.UniversalQuery);
    3. manager.CompleteAllJobs();
    4. SceneManager.LoadScene(0);
    But I keep getting this error:
    InvalidOperationException: The previously scheduled job HavokSimulation:SyncJob reads from the Unity.Collections.NativeParallelHashMap`2[Unity.Entities.Entity,System.Int32] SyncJob.World.CollisionWorld.EntityBodyIndexMap. You must call JobHandle.Complete() on the job HavokSimulation:SyncJob, before you can write to the Unity.Collections.NativeParallelHashMap`2[Unity.Entities.Entity,System.Int32] safely.
    Unity.Collections.LowLevel.Unsafe.AtomicSafetyHandle.CheckWriteAndBumpSecondaryVersion (Unity.Collections.LowLevel.Unsafe.AtomicSafetyHandle handle) (at <24d45e813e524a99bfb7a145158a7980>:0)
    Unity.Collections.NativeParallelHashMap`2[TKey,TValue].CheckWrite () (at Library/PackageCache/com.unity.collections@1.4.0/Unity.Collections/NativeParallelHashMap.cs:558)
    Unity.Collections.NativeParallelHashMap`2[TKey,TValue].Clear () (at Library/PackageCache/com.unity.collections@1.4.0/Unity.Collections/NativeParallelHashMap.cs:196)
    Unity.Physics.CollisionWorld.Reset (System.Int32 numStaticBodies, System.Int32 numDynamicBodies) (at Library/PackageCache/com.unity.physics@0.51.1-preview.21/Unity.Physics/Collision/World/CollisionWorld.cs:53)
    Unity.Physics.PhysicsWorld.Reset (System.Int32 numStaticBodies, System.Int32 numDynamicBodies, System.Int32 numJoints) (at Library/PackageCache/com.unity.physics@0.51.1-preview.21/Unity.Physics/Dynamics/World/PhysicsWorld.cs:41)

    I'm assuming I have to wait for some physics job to complete, any ideas?