Search Unity

  1. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Bug Spawning a gameobject with destroyWithScene=False right before switching scene is not working

Discussion in 'Netcode for GameObjects' started by darklanx, Sep 9, 2023.

  1. darklanx


    May 21, 2015
    I'm immediately spawning a gameobject right before I'm switching scene.
    Code (CSharp):
    1. if (NetworkManager.Singleton.IsServer)
    2. {
    3.     GameObject go = Instantiate(ServerCommunicatorPrefab);
    4.     go.GetComponent<NetworkObject>().Spawn(destroyWithScene: false);
    5. }
    And the object got destroyed anyway.
    I have to manually setup DontDestroyOnLoad in the objects OnNetworkSpawn to prevent it getting destroyed.