Search Unity

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

Bug Destroy a spawned NetworkObject on a non-host client is not valid

Discussion in 'Netcode for GameObjects' started by Maxim, Sep 17, 2023.

  1. Maxim

    Maxim

    Joined:
    Aug 17, 2009
    Posts:
    37
    Hello,

    If a server spawns NetworkObjects while a client connects to the already running game, I get this error:

    Client error:
    [Netcode] Destroy a spawned NetworkObject on a non-host client is not valid. Call Destroy or Despawn on the server/host instead.
    ...
    (at ./Library/PackageCache/com.unity.netcode.gameobjects@1.6.0/Runtime/Core/NetworkObject.cs:556)

    Server error:
    [Netcode-Server Sender=1] Destroy a spawned NetworkObject on a non-host client is not valid. Call Destroy or Despawn on the server/host instead.

    In my NetManager:
    Code (CSharp):
    1. NetworkManager.Singleton.OnServerStarted += OnServerStarted;
    2.  
    3. private void OnServerStarted()
    4. {
    5.    Debug.Log($"SteamManager.OnServerStarted");
    6.    NetworkManager.Singleton.SceneManager.LoadScene(gameSceneName, LoadSceneMode.Single);
    7. }
    NetworkManager's Scene management is enabled. Client loads a scene automatically with
    NetworkManager.Singleton.StartClient()
    Unity 2022.3.7f1 LTS
    Tried 2 transports, both have the problem:
    Unity transport, host and client on the same pc;
    Facepunch.
    No lobby. Just main menu scene -> host or join -> game scene
    I suppose, a game scene has to be quite complex, so it would load several seconds at least.
    Also, maybe a game scene has to contain a bunch of already spawned network objects.
     
    Last edited: Sep 17, 2023
  2. Maxim

    Maxim

    Joined:
    Aug 17, 2009
    Posts:
    37

    Attached Files:

    Last edited: Sep 19, 2023
  3. cerestorm

    cerestorm

    Joined:
    Apr 16, 2020
    Posts:
    638
    I took a look at the project. Some spheres are being spawned on the client in the Menu scene before the network scene manager switches to the Game scene. I reproduced the issue in another project spawning in Update and running at 1 fps you can see it happening, I logged the scene the sphere was spawning in just to be sure. This looks like quite a major bug to me and I'd highly recommend you report the issue on the NGO Github. Nevermind, you did :D
     
    Last edited: Sep 19, 2023
  4. jackward84

    jackward84

    Joined:
    Jan 26, 2017
    Posts:
    87
    I believe I ran into the same issue today while playtesting, but it's very difficult to tell due to vague error messages. I received the message that I had destroyed a network object as a client, but scouring my entire codebase of destroys and despawns, I could not find any possible offenders. Whatever it was, it happened when connecting to a server that already had players in it. From that point, the game could not recover. Every frame was an NGO crash. No errors on the server. This crash persisted after shutting down the networkmanager and connecting to another assignment, a full game restart was required to get the game functioning again. NGO 1.5.2
     
  5. cerestorm

    cerestorm

    Joined:
    Apr 16, 2020
    Posts:
    638
    Last edited: Sep 19, 2023
    Maxim likes this.
  6. edgeworks

    edgeworks

    Joined:
    Jun 3, 2023
    Posts:
    1
    This is such a major bug I dont understand how this can be overlooked for so long... still not fixed ):
     
    Maxim likes this.