InvalidOperationException: object is not initialized or has already been destroyed

I’ve suddenly begun receiving this error after exiting play-mode.
It repeats indefinitely, each editor update, until I reload assemblies. Any idea what could be causing this?

2 Likes

Same here, after updating to 0.10.0 I saw, that all Worlds get destroyed and recreated for some reason just after player load. And if I created any Entities in MonoBehaviour Start method and have any managed components with references to Meshes, they get destroyed too. And after that everythig is exploded with null refs.

But if I delay creation of entites by the one frame, everything continue to work.

Sometimes Worlds recreated after additive scene load.

Same error using 0.10.0 I keep getting “object is not initialized or has already been destroyed” when I try to use World. My world is destroyed or not created and I don’t know what to do

FULL ERROR :

InvalidOperationException: object is not initialized or has already been destroyed
Unity.Entities.ComponentSystemBase.CheckedState () (at Library/PackageCache/com.unity.entities@0.10.0-preview.6/Unity.Entities/ComponentSystemBase.cs:331)
Unity.Entities.ComponentSystemBase.set_Enabled (System.Boolean value) (at Library/PackageCache/com.unity.entities@0.10.0-preview.6/Unity.Entities/ComponentSystemBase.cs:343)
DOTS_GameHandler.SetSystemsEnabled (System.Boolean enabled) (at Assets/DOTS_FlappyBird/Scripts/DOTS_GameHandler.cs:58)
DOTS_GameHandler.OnCreate () (at Assets/DOTS_FlappyBird/Scripts/DOTS_GameHandler.cs:20)
Unity.Entities.ComponentSystemBase.CreateInstance (Unity.Entities.World world) (at Library/PackageCache/com.unity.entities@0.10.0-preview.6/Unity.Entities/ComponentSystemBase.cs:434)
Unity.Entities.World.AddSystem_OnCreate_Internal (Unity.Entities.ComponentSystemBase system) (at Library/PackageCache/com.unity.entities@0.10.0-preview.6/Unity.Entities/World.cs:417)
Unity.Entities.World.GetOrCreateSystemsAndLogException (System.Type[] types) (at Library/PackageCache/com.unity.entities@0.10.0-preview.6/Unity.Entities/World.cs:614)
UnityEngine.Debug:LogException(Exception)
Unity.Debug:LogException(Exception) (at Library/PackageCache/com.unity.entities@0.10.0-preview.6/Unity.Entities/Stubs/Unity/Debug.cs:19)
Unity.Entities.World:GetOrCreateSystemsAndLogException(Type[]) (at Library/PackageCache/com.unity.entities@0.10.0-preview.6/Unity.Entities/World.cs:618)
Unity.Entities.DefaultWorldInitialization:AddSystemsToRootLevelSystemGroups(World, Type[]) (at Library/PackageCache/com.unity.entities@0.10.0-preview.6/Unity.Entities.Hybrid/Injection/DefaultWorldInitialization.cs:127)
Unity.Entities.DefaultWorldInitialization:Initialize(String, Boolean) (at Library/PackageCache/com.unity.entities@0.10.0-preview.6/Unity.Entities.Hybrid/Injection/DefaultWorldInitialization.cs:106)
Unity.Entities.AutomaticWorldBootstrap:Initialize() (at Library/PackageCache/com.unity.entities@0.10.0-preview.6/Unity.Entities.Hybrid/Injection/AutomaticWorldBootstrap.cs:15)

For me this issue solved itself when I unpinned and closed Entity Debugger window and opened it again.

7 Likes

I am getting this for NetCode’s ClientPresentationSystemGroup:

InvalidOperationException: object is not initialized or has already been destroyed
Unity.Entities.ComponentSystemBase.CheckedState () (at Library/PackageCache/com.unity.entities@0.11.0-preview.7/Unity.Entities/ComponentSystemBase.cs:333)
Unity.Entities.JobComponentSystem.Update () (at Library/PackageCache/com.unity.entities@0.11.0-preview.7/Unity.Entities/JobComponentSystem.cs:109)
Unity.Entities.ComponentSystemGroup.UpdateAllSystems () (at Library/PackageCache/com.unity.entities@0.11.0-preview.7/Unity.Entities/ComponentSystemGroup.cs:445)
UnityEngine.Debug:LogException(Exception)
Unity.Debug:LogException(Exception) (at Library/PackageCache/com.unity.entities@0.11.0-preview.7/Unity.Entities/Stubs/Unity/Debug.cs:19)
Unity.Entities.ComponentSystemGroup:UpdateAllSystems() (at Library/PackageCache/com.unity.entities@0.11.0-preview.7/Unity.Entities/ComponentSystemGroup.cs:450)
Unity.Entities.ComponentSystemGroup:OnUpdate() (at Library/PackageCache/com.unity.entities@0.11.0-preview.7/Unity.Entities/ComponentSystemGroup.cs:398)
Unity.NetCode.ClientPresentationSystemGroup:OnUpdate() (at Library/PackageCache/com.unity.netcode@0.2.0-preview.5/Runtime/ClientServerWorld/ClientPresentationSystemGroup.cs:22)
Unity.Entities.ComponentSystem:Update() (at Library/PackageCache/com.unity.entities@0.11.0-preview.7/Unity.Entities/ComponentSystem.cs:109)
Unity.Entities.ComponentSystemGroup:UpdateAllSystems() (at Library/PackageCache/com.unity.entities@0.11.0-preview.7/Unity.Entities/ComponentSystemGroup.cs:445)
Unity.Entities.ComponentSystemGroup:OnUpdate() (at Library/PackageCache/com.unity.entities@0.11.0-preview.7/Unity.Entities/ComponentSystemGroup.cs:398)
Unity.Entities.ComponentSystem:Update() (at Library/PackageCache/com.unity.entities@0.11.0-preview.7/Unity.Entities/ComponentSystem.cs:109)
Unity.Entities.ComponentSystemGroup:UpdateAllSystems() (at Library/PackageCache/com.unity.entities@0.11.0-preview.7/Unity.Entities/ComponentSystemGroup.cs:445)
Unity.Entities.ComponentSystemGroup:OnUpdate() (at Library/PackageCache/com.unity.entities@0.11.0-preview.7/Unity.Entities/ComponentSystemGroup.cs:398)
Unity.Entities.ComponentSystem:Update() (at Library/PackageCache/com.unity.entities@0.11.0-preview.7/Unity.Entities/ComponentSystem.cs:109)
Unity.Entities.DummyDelegateWrapper:TriggerUpdate() (at Library/PackageCache/com.unity.entities@0.11.0-preview.7/Unity.Entities/ScriptBehaviourUpdateOrder.cs:192)
UnityEditor.EditorApplication:Step()
Unity.Entities.Editor.LiveLinkToolbar:smile:rawPlaybar(CommandExecuteContext) (at Library/PackageCache/com.unity.entities@0.11.0-preview.7/Unity.Entities.Editor/LiveLink/LiveLinkToolbar.cs:80)
UnityEngine.GUIUtility:ProcessEvent(Int32, IntPtr, Boolean&)

Thank you

Temporary fix of EntiyDebugger.cs for anybody who is experiencing null refs after they leave play mode while having an entity selected.

At line 377 wrap the Repaint() code block in try catch

                try
                {
                    if (systemListView.NeedsReload || entityQueryListView.NeedsReload || entityListView.NeedsReload || !filterUI.TypeListValid())
                        Repaint();
                }
                catch (Exception ex)
                {
                }

Line 537 OnGui() code block with LayoutEvent

            try
            {
                if (Event.current.type == EventType.Layout)
                {
                    systemListView.ReloadIfNecessary();
                    filterUI.GetTypes();
                    entityQueryListView.ReloadIfNecessary();
                    entityListView.ReloadIfNecessary();
                }
            }
            catch(Exception ex)
            {
            }

To keep the changes after you restart Editor simply go to

C:\Users%USERNAME%\AppData\Local\Unity\cache\packages\packages.unity.com\com.unity.entities@yourPackageVersion\Unity.Entities.Editor\EntityDebugger and replace EntityDebugger.cs with the above changes.

1 Like