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. Dismiss Notice

Resolved PhysicsWorldHistroy errors when upgrading to 0.50

Discussion in 'NetCode for ECS' started by Dan-Foster, Mar 22, 2022.

  1. Dan-Foster

    Dan-Foster

    Joined:
    Aug 7, 2019
    Posts:
    48
    Hi there.

    I'm in the process of upgrading a project to Entities / NetCode 0.50.

    I've hit a snag that I'm not sure about. I'm trying to use PhysicsWorldHistroy to move the players around using raycast.

    I've created a singleton for LagCompensationConfig That's spawned in a System's OnCreate().

    Now I'm getting an error that starts with:
    ObjectDisposedException: Cannot access a disposed object.
    Object name: 'The NativeArray has been disposed, it is not allowed to access it'.

    happening from the PhysicsWorldHistory.Update() function.

    - Full stack trace below.

    Am I missing something as part of the setup in NetCode 0.50?

    Unity Version 2020.3.31f1
    Entities 0.50,
    NetCode 0.50,

    Thanks,

    ObjectDisposedException: Cannot access a disposed object.
    Object name: 'The NativeArray has been disposed, it is not allowed to access it'.
    Unity.Collections.LowLevel.Unsafe.AtomicSafetyHandle.CheckExistsAndThrow (Unity.Collections.LowLevel.Unsafe.AtomicSafetyHandle& handle) (at <3be1a7ff939c43f181c0a10b5a0189ac>:0)
    Unity.Collections.LowLevel.Unsafe.AtomicSafetyHandle.ValidateNonDefaultHandle (Unity.Collections.LowLevel.Unsafe.AtomicSafetyHandle& handle) (at <3be1a7ff939c43f181c0a10b5a0189ac>:0)
    Unity.Collections.NativeArray`1[T].get_Length () (at <3be1a7ff939c43f181c0a10b5a0189ac>:0)
    Unity.Physics.Broadphase+Tree.get_NumBodies () (at Library/PackageCache/com.unity.physics@0.50.0-preview.24/Unity.Physics/Collision/World/Broadphase.cs:375)
    Unity.Physics.Broadphase.get_NumStaticBodies () (at Library/PackageCache/com.unity.physics@0.50.0-preview.24/Unity.Physics/Collision/World/Broadphase.cs:28)
    Unity.Physics.CollisionWorld.get_NumBodies () (at Library/PackageCache/com.unity.physics@0.50.0-preview.24/Unity.Physics/Collision/World/CollisionWorld.cs:23)
    Unity.NetCode.CollisionHistoryBuffer.CloneCollisionWorld (System.Int32 index, Unity.Physics.CollisionWorld& collWorld) (at Library/PackageCache/com.unity.netcode@0.50.0-preview.29/Runtime/Physics/PhysicsWorldHistory.cs:194)
    Unity.NetCode.PhysicsWorldHistory.OnUpdate () (at Library/PackageCache/com.unity.netcode@0.50.0-preview.29/Runtime/Physics/PhysicsWorldHistory.cs:374)
    Unity.Entities.SystemBase.Update () (at Library/PackageCache/com.unity.entities@0.50.0-preview.24/Unity.Entities/SystemBase.cs:409)
    Unity.Entities.ComponentSystemGroup.UpdateAllSystems () (at Library/PackageCache/com.unity.entities@0.50.0-preview.24/Unity.Entities/ComponentSystemGroup.cs:583)
    UnityEngine.Debug:LogException(Exception)
    Unity.Debug:LogException(Exception) (at Library/PackageCache/com.unity.entities@0.50.0-preview.24/Unity.Entities/Stubs/Unity/Debug.cs:19)
    Unity.Entities.ComponentSystemGroup:UpdateAllSystems() (at Library/PackageCache/com.unity.entities@0.50.0-preview.24/Unity.Entities/ComponentSystemGroup.cs:588)
    Unity.Entities.ComponentSystemGroup:OnUpdate() (at Library/PackageCache/com.unity.entities@0.50.0-preview.24/Unity.Entities/ComponentSystemGroup.cs:523)
    Unity.Entities.ComponentSystem:Update() (at Library/PackageCache/com.unity.entities@0.50.0-preview.24/Unity.Entities/ComponentSystem.cs:114)
    Unity.Entities.ComponentSystemGroup:UpdateAllSystems() (at Library/PackageCache/com.unity.entities@0.50.0-preview.24/Unity.Entities/ComponentSystemGroup.cs:583)
    Unity.Entities.ComponentSystemGroup:OnUpdate() (at Library/PackageCache/com.unity.entities@0.50.0-preview.24/Unity.Entities/ComponentSystemGroup.cs:523)
    Unity.NetCode.ServerSimulationSystemGroup:OnUpdate() (at Library/PackageCache/com.unity.netcode@0.50.0-preview.29/Runtime/ClientServerWorld/ServerSimulationSystemGroup.cs:124)
    Unity.Entities.ComponentSystem:Update() (at Library/PackageCache/com.unity.entities@0.50.0-preview.24/Unity.Entities/ComponentSystem.cs:114)
    Unity.Entities.ComponentSystemGroup:UpdateAllSystems() (at Library/PackageCache/com.unity.entities@0.50.0-preview.24/Unity.Entities/ComponentSystemGroup.cs:583)
    Unity.Entities.ComponentSystemGroup:OnUpdate() (at Library/PackageCache/com.unity.entities@0.50.0-preview.24/Unity.Entities/ComponentSystemGroup.cs:523)
    Unity.Entities.ComponentSystem:Update() (at Library/PackageCache/com.unity.entities@0.50.0-preview.24/Unity.Entities/ComponentSystem.cs:114)
    Unity.Entities.ComponentSystemGroup:UpdateAllSystems() (at Library/PackageCache/com.unity.entities@0.50.0-preview.24/Unity.Entities/ComponentSystemGroup.cs:583)
    Unity.Entities.ComponentSystemGroup:OnUpdate() (at Library/PackageCache/com.unity.entities@0.50.0-preview.24/Unity.Entities/ComponentSystemGroup.cs:523)
    Unity.Entities.ComponentSystem:Update() (at Library/PackageCache/com.unity.entities@0.50.0-preview.24/Unity.Entities/ComponentSystem.cs:114)
    Unity.Entities.DummyDelegateWrapper:TriggerUpdate() (at Library/PackageCache/com.unity.entities@0.50.0-preview.24/Unity.Entities/ScriptBehaviourUpdateOrder.cs:426)
     
    Lukas_Kastern likes this.
  2. Lukas_Kastern

    Lukas_Kastern

    Joined:
    Aug 31, 2018
    Posts:
    97
    Dan-Foster likes this.
  3. Dan-Foster

    Dan-Foster

    Joined:
    Aug 7, 2019
    Posts:
    48
    Woah thanks for the fast reply!

    I've just moved the netcode package to the Packages folder, but now when I open the project I'm getting
    "error Netcode: System.IO.FileNotFoundException: Cannot load template"

    Microsoft (R) Visual C# Compiler version 3.8.0-dev.20527.1 (53dc6556)
    Copyright (C) Microsoft Corporation. All rights reserved.

    error Netcode: System.IO.FileNotFoundException: Cannot load template Packages/com.unity.netcode/Editor/Templates/GhostComponentSerializer.cs. Package com.unity.netcode not found
    at Unity.NetCode.Generators.PathResolver.ResolvePath(String templatePath)
    at Unity.NetCode.Generators.GhostCodeGen..ctor(String template, PathResolver resolver, IDiagnosticReporter reporter)
    at Unity.NetCode.Generators.ComponentGenerator..ctor(Context context)
    at Unity.NetCode.Generators.CodeGenerator.InternalGenerateType(Context context, TypeInformation type, String fullFieldName)
    at Unity.NetCode.Generators.CodeGenerator.GenerateGhost(Context context, TypeInformation typeTree)
    at Unity.NetCode.Generators.ComponentFactory.GenerateComponents(IEnumerable`1 components, Compilation compilation, Context codeGenContext)
    at Unity.NetCode.Generators.ComponentFactory.Generate(IReadOnlyList`1 componentsCandidates, IReadOnlyList`1 variantsCandidates, Compilation compilation, Context codeGenContext)
    at Unity.NetCode.Generators.NetCodeSourceGenerator.Generate(GeneratorExecutionContext executionContext, Candidates candidates, IDiagnosticReporter diagnostic)
    at Unity.NetCode.Generators.NetCodeSourceGenerator.Execute(GeneratorExecutionContext executionContext)
    Packages\com.unity.netcode@0.50.0-preview.29\Runtime\NetDebug.cs(58,17): warning CS0618: 'UnsafeList' is obsolete: 'Untyped UnsafeList is deprecated, please use UnsafeList<T> instead. (RemovedAfter 2021-05-18)'
    Packages\com.unity.netcode@0.50.0-preview.29\Runtime\NetDebug.cs(76,28): warning CS0618: 'UnsafeList' is obsolete: 'Untyped UnsafeList is deprecated, please use UnsafeList<T> instead. (RemovedAfter 2021-05-18)'

    This is something I never had when moving NetCode 0.6. I've tried deleting my Library folder in the hope it would re-generate NetCode serialization files, but no luck.

    I'm not sure at all what this error is about.
     
  4. Dan-Foster

    Dan-Foster

    Joined:
    Aug 7, 2019
    Posts:
    48
    Oh I've fixed it! It's complaining about the path of a file in the NetCode package.

    I had directly copied the NetCode folder from the cache without changing it's name, so it was called "com.unity.netcode@0.50.0-preview.29"

    I renamed the folder so it looked like this
    "Packages/com.unity.netcode"
    And the error's gone.
     
    Lukas_Kastern likes this.
  5. Dan-Foster

    Dan-Foster

    Joined:
    Aug 7, 2019
    Posts:
    48
    The next issue I'm having with the prediction here is that there doesn't seem to be any ghost snapshot data on my player. I'm getting this warning log out each frame.

    "Trying to predict a ghost without having a state to roll back to 0 / 697"

    Trying to predict a ghost without having a state to roll back to 0 / 697
    UnityEngine.Debug:LogWarning (object)
    Unity.NetCode.NetDebug:LogWarning (Unity.Collections.FixedString512Bytes&) (at Packages/com.unity.netcode/Runtime/NetDebug.cs:349)
    Unity.NetCode.GhostUpdateSystem/UpdateJob:Execute (Unity.Entities.ArchetypeChunk,int,int) (at Packages/com.unity.netcode/Runtime/Snapshot/GhostUpdateSystem.cs:220)
    Unity.Entities.JobChunkExtensions/JobChunkProducer`1<Unity.NetCode.GhostUpdateSystem/UpdateJob>:ExecuteInternal (Unity.Entities.JobChunkExtensions/JobChunkWrapper`1<Unity.NetCode.GhostUpdateSystem/UpdateJob>&,intptr,Unity.Jobs.LowLevel.Unsafe.JobRanges&,int) (at Library/PackageCache/com.unity.entities@0.50.0-preview.24/Unity.Entities/IJobChunk.cs:401)
    Unity.Entities.JobChunkExtensions/JobChunkProducer`1<Unity.NetCode.GhostUpdateSystem/UpdateJob>:Execute (Unity.Entities.JobChunkExtensions/JobChunkWrapper`1<Unity.NetCode.GhostUpdateSystem/UpdateJob>&,intptr,intptr,Unity.Jobs.LowLevel.Unsafe.JobRanges&,int) (at Library/PackageCache/com.unity.entities@0.50.0-preview.24/Unity.Entities/IJobChunk.cs:368)


    The player's ghost is set to Predicted, and was working fine before upgrade.