Skip to content

Some NetworkObjects do not despawn (get destroyed) on client while disabled on disconnect #3899

Closed

Description

@Squashi11

Description

Some NetworkObjects do not despawn (get destroyed) on client while disabled on disconnect. The NetworkObjects stay spawned in client scene even when the host disconnects / client leaves

Reproduce Steps

  1. Spawn and disable a network object on client + host
  2. Disconnect client / host
  3. The NetworkObject stays on client even though the owner is server

Actual Outcome

NetworkObject stays spawned and disabled in client scene when host ends session

Expected Outcome

The GameObject should have been despawned and destroyed

Screenshots

(from client) the host disconnected and the NetworkObjects stayed on hierarchy spawned

Image Image Image

Environment

  • OS: Windows 11
  • Unity Version: 6000.3.11f1
  • Netcode Version: 2.10.0
  • Netcode Commit: ?
  • Netcode Topology: Host - Client

Additional Context

I can provide more logs if needed, but afaik we just spawn resources in our game and then disable them if they get destroyed (dont despawn for pooling) and then enable them again if the player refreshes the map

Activity

  1. EmandM commented on Mar 16, 2026

    @EmandM
    Member

    Just for sanity, do you mind verifying if DontDestroyWithOwner is false for all of these objects?

    Otherwise, is there any chance you can drop your LogLevel down to Developer and share the logs when the host leaves the session? If the host is leaving the session then it should not be possible for the client to see any spawned objects as there shouldn't be a session for them to be spawned in. It definitely looks like might have found an edge case issue here.

  2. added
    stat:awaiting-responseAwaiting response from author. This label should be added manually.
    and removed on Mar 16, 2026
  3. Squashi11 commented on Mar 17, 2026

    @Squashi11
    Author

    Thanks a lot for the quick reply! I checked the prefab and the spawned objects and the DontDestroyWithOwner is set to default value FALSE.
    After turning on the developer log level I noticed there MIGHT be some problems happening

    Image

    I will try to look at all of these and get back if the error still persists. Thanks for the insight

  4. added and removed
    stat:awaiting-responseAwaiting response from author. This label should be added manually.
    on Mar 17, 2026
  5. Squashi11 commented on Mar 17, 2026

    @Squashi11
    Author

    Upon exiting play mode this error occurs numerous times

    Image
  6. EmandM commented on Mar 17, 2026

    @EmandM
    Member

    Oooh, that is very strange. It looks like maybe the NetworkManager is ending up destroyed before anything else which is breaking stuff unexpectedly. Do you know if this used to work and is now broken?

  7. added
    stat:awaiting-responseAwaiting response from author. This label should be added manually.
    and removed on Mar 17, 2026
  8. NoelStephensUnity commented on Mar 17, 2026

    @NoelStephensUnity
    Member

    Hi @Squashi11,

    Just to add to @EmandM's question:
    Do you use the UnityEngine.SceneManagement.SceneManager to load something upon disconnecting from a session? If so, when is that being invoked?

  9. 22 remaining items

  10. added
    stat:importStatus - Issue is going to be saved internally
    on Apr 8, 2026
  11. added
    stat:importedStatus - Issue is tracked internally at Unity
    and removed
    stat:importStatus - Issue is going to be saved internally
    on Apr 20, 2026
  12. NoelStephensUnity commented on Jul 16, 2026

    @NoelStephensUnity
    Member

    @Squashi11
    Thank you for submitting your project as that greatly helped me narrow down the underlying issues.

    When scene management is disabled

    Since your NetworkManager has scene management disabled, in-scene placed NetworkObjects that are not network prefab instances that are registered with a hash override will not get synchronized.

    Image Clouds server spawner does not get spawned because it is not a prefab instance and does not have an override entry for the instance in the scene.

    To resolve this issue:

    • Make Clouds Server Spawner a prefab by dragging it into a preferred folder under your prefabs directory.
    • Delete the instance in the scene.
    • Drag and drop the newly created prefab into the scene.
    • Right click on the DefaultNetworkPrefabs list and select properties to create a 2nd "inspector view/properties" window.
    • Select the prefab instance you just created from the new prefab that is in the scene.
    • Copy that instance's prefab hash value.
    • In the DefaultNetworkPrefabs view, click the override checkbox next to the Clouds Server Spawner prefab.
    • Select Hash for the override type
    • Paste the in-scene prefab instance's GlobalObjectIdHash value in the field next to the Hash selection.
    • Drag and drop the actual newly create prefab (not the one in the scene) into the overriding prefab field.
    • Save and test.

    Reference to the setup:
    Image

    What it should look like when you are done with that entry.
    Image

    Dynamically spawned NetworkObjects must be network prefabs created in the editor

    For some of the other NetworkObjects not being spawned, within your BasePoolManager class there is this method:

        private void CreateParent()
        {
            pooledObjectsParent = new GameObject(GetPooledObjectsParentName()).transform;
            if (UseNetworkedParent())
            {
                NetworkObject networkSranda = pooledObjectsParent.gameObject.AddComponent<NetworkObject>();
                networkSranda.Spawn();
            }
        }

    Dynamically creating NetworkObjects during runtime is not supported by NGO and will not synchronize properly. Anywhere you are doing this, I would make those actual network prefabs within the editor (while not in play mode) and then spawn instances of those.

    Why?
    NetworkObject prefabs and/or in-scene placed NetworkObjects will generate a GlobalObjectIdHash value while in the editor and not play mode. This cannot be done during runtime as the clients need to already have the GlobalObjectIdHash on their end to know "what thing should the client create an instance of". Additionally, when creating them dynamically (like the above script) during runtime, the GlobalObjectIdHash value will end up being 0 for every instance.

    The rule of thumb is for creating a GameObject with a NetworkObject instance is to create a network prefab or within a scene all within the editor (when not in play mode).

    How this was tested

    Within MainGameLogic.cs:

    • Set isLocalTesting to true.
    • I added the following using directive:
    #if UNITY_EDITOR
    using Unity.Multiplayer.PlayMode;
    #endif
    • Within the MainGameLogic.Custom method
        private async void Custom()
        {
            startHost = !CurrentPlayer.IsMainEditor;

    This allowed me to run the host within the editor window and the client within the MPPM virtual client.
    (I would highly recommend adding some UI to handle this)

    I was running Unity 6000.4 and using the most current version of NGO (yet to be released...but will be available very soon).
    You can test the above modifications with v2.12.0 or use the soon to be released version by temporarily replacing your manifest.json entry for com.unity.netcode.gameobjects with this:

    "com.unity.netcode.gameobjects": "https://github.com/Unity-Technologies/com.unity.netcode.gameobjects.git?path=com.unity.netcode.gameobjects#develop-2.0.0",
    

    Let me know if these findings resolve your issues.

  13. NoelStephensUnity commented on Aug 13, 2026

    @NoelStephensUnity
    Member

    @Squashi11
    We are closing this issue as we were not able to replicate it and have provided a working example of how to accomplish what you were trying to accomplish. If you feel this is still an issue please feel free to re-open it or post additional findings here.

  14. Squashi11 commented on Aug 14, 2026

    @Squashi11
    Author

    Thanks a lot for your extensive reply and sorry for my inactivity in this thread! This has helped us immensely and we managed to fix all the issues. For the objects not de-spawning issue = we fixed it by updating to the latest version when it came out, so it looked like a fixed bug. For now we have no more issues, thanks a lot for your time on this matter.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

stat:importedStatus - Issue is tracked internally at Unitytype:supportQuestions or other support

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions