Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Join us on March 30, 2023, between 5 am & 1 pm EST, in the Performance Profiling Dev Blitz Day 2023 - Q&A forum and Discord where you can connect with our teams behind the Memory and CPU Profilers.
    Dismiss Notice

Bug InvalidOperationException when cloning a CollisionWorld

Discussion in 'Physics for ECS' started by alfiare, Jan 26, 2023.

  1. alfiare

    alfiare

    Joined:
    Feb 10, 2017
    Posts:
    29
    I'm upgrading to the 1.0 version and I clone the collision world so I can hand it off to a rather long running job that uses it for a bunch of things. I'm trying to do this with the following inside a SystemBase system...

    Code (CSharp):
    1. RefRW<PhysicsWorldSingleton> physicsWorldSingleton = SystemAPI.GetSingletonRW<PhysicsWorldSingleton>();
    2.             _clonedWorld = physicsWorldSingleton.ValueRW.PhysicsWorld.CollisionWorld.Clone();
    But it always throws this error...
    InvalidOperationException: The previously scheduled job Broadphase:prepareStaticBodyDataJob writes to the UNKNOWN_OBJECT_TYPE PrepareStaticBodyDataJob.FiltersOut. You must call JobHandle.Complete() on the job Broadphase:prepareStaticBodyDataJob, before you can read from the UNKNOWN_OBJECT_TYPE safely.
    Unity.Collections.LowLevel.Unsafe.AtomicSafetyHandle.CheckReadAndThrowNoEarlyOut (Unity.Collections.LowLevel.Unsafe.AtomicSafetyHandle handle) (at <bdd20210bb844b2e88e1149ea99da5ef>:0)
    Unity.Collections.LowLevel.Unsafe.AtomicSafetyHandle.CheckReadAndThrow (Unity.Collections.LowLevel.Unsafe.AtomicSafetyHandle handle) (at <bdd20210bb844b2e88e1149ea99da5ef>:0)
    Unity.Collections.NativeArray`1[T]..ctor (Unity.Collections.NativeArray`1[T] array, Unity.Collections.Allocator allocator) (at <bdd20210bb844b2e88e1149ea99da5ef>:0)
    Unity.Physics.Broadphase+Tree.Clone () (at Library/PackageCache/com.unity.physics@1.0.0-pre.15/Unity.Physics/Collision/World/Broadphase.cs:443)
    Unity.Physics.Broadphase.Clone () (at Library/PackageCache/com.unity.physics@1.0.0-pre.15/Unity.Physics/Collision/World/Broadphase.cs:58)
    Unity.Physics.CollisionWorld.Clone () (at Library/PackageCache/com.unity.physics@1.0.0-pre.15/Unity.Physics/Collision/World/CollisionWorld.cs:118)
    StratheonMin.Client.TypeSystem.Plans.ECS.Systems.ConnectionValidatorSystem.LaunchValidationJob () (at Assets/Assemblies/StratheonMin.Client/TypeSystem/Plans/ECS/Systems/ConnectionValidatorSystem.cs:112)
    StratheonMin.Client.TypeSystem.Plans.ECS.Systems.ConnectionValidatorSystem.InternalOnUpdate (Unity.Jobs.JobHandle inputDeps) (at Assets/Assemblies/StratheonMin.Client/TypeSystem/Plans/ECS/Systems/ConnectionValidatorSystem.cs:83)
    StratheonMin.Client.PlanBuilder.ECS.Systems.ClientConnectionValidatorSystem.InternalOnUpdate (Unity.Jobs.JobHandle inputDeps) (at Assets/Assemblies/StratheonMin.Client/PlanBuilder/ECS/Systems/ClientConnectionValidatorSystem.cs:35)
    StratheonMin.Client.TypeSystem.Plans.ECS.Systems.BasePlanSystem.CallInternalOnOpdate () (at Assets/Assemblies/StratheonMin.Client/TypeSystem/Plans/ECS/Systems/BasePlanSystem.cs:33)
    StratheonMin.Client.TypeSystem.Plans.ECS.Systems.BasePlanSystem.OnUpdate () (at Assets/Assemblies/StratheonMin.Client/TypeSystem/Plans/ECS/Systems/BasePlanSystem.cs:28)
    Unity.Entities.SystemBase.Update () (at Library/PackageCache/com.unity.entities@1.0.0-pre.15/Unity.Entities/SystemBase.cs:428)
    Unity.Entities.ComponentSystemGroup.UpdateAllSystems () (at Library/PackageCache/com.unity.entities@1.0.0-pre.15/Unity.Entities/ComponentSystemGroup.cs:670)
    UnityEngine.Debug:LogException(Exception)
    Unity.Debug:LogException(Exception) (at Library/PackageCache/com.unity.entities@1.0.0-pre.15/Unity.Entities/Stubs/Unity/Debug.cs:19)
    Unity.Entities.ComponentSystemGroup:UpdateAllSystems() (at Library/PackageCache/com.unity.entities@1.0.0-pre.15/Unity.Entities/ComponentSystemGroup.cs:675)
    Unity.Entities.ComponentSystemGroup:OnUpdate() (at Library/PackageCache/com.unity.entities@1.0.0-pre.15/Unity.Entities/ComponentSystemGroup.cs:628)
    Unity.Entities.SystemBase:Update() (at Library/PackageCache/com.unity.entities@1.0.0-pre.15/Unity.Entities/SystemBase.cs:416)
    Unity.Entities.ComponentSystemGroup:UpdateAllSystems() (at Library/PackageCache/com.unity.entities@1.0.0-pre.15/Unity.Entities/ComponentSystemGroup.cs:670)
    Unity.Entities.ComponentSystemGroup:OnUpdate() (at Library/PackageCache/com.unity.entities@1.0.0-pre.15/Unity.Entities/ComponentSystemGroup.cs:628)
    Unity.Entities.SystemBase:Update() (at Library/PackageCache/com.unity.entities@1.0.0-pre.15/Unity.Entities/SystemBase.cs:416)
    Unity.Entities.DummyDelegateWrapper:TriggerUpdate() (at Library/PackageCache/com.unity.entities@1.0.0-pre.15/Unity.Entities/ScriptBehaviourUpdateOrder.cs:526)


    Am I doing this wrong? I used to use the call to RegisterPhysicsSystemsReadOnly() in the system startup in the previous version but the docs for the current version say that's been removed in favor of the new GetSingletonRW call.
     
  2. JosepMariaPujol

    JosepMariaPujol

    Unity Technologies

    Joined:
    Jun 16, 2021
    Posts:
    77
    Hey @alfiare, I will look into this issue. Thanks for reporting!
     
    alfiare likes this.