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.

Resolved Spawn is not shown for player join mid game

Discussion in 'Netcode for GameObjects' started by scarffy, Dec 31, 2021.

  1. scarffy

    scarffy

    Joined:
    Jan 15, 2013
    Posts:
    25
    Hello,

    I have created a spawn script for object whenever player spawn. This script works fine for player who are already in the scene. The problem happens when new player join mid session. This new player can't see whatever object that are instantiated by players who are already in the scene.

    I follow the code that was given in the documentation.

    Code (CSharp):
    1. GameObject go = Instantiate(NetworkController.Instance.hostUI, NetworkController.Instance.canvasParent);
    2. go.GetComponent<NetworkObject>().Spawn();
    from my understanding, code from line 2 is enough for new player joining mid session to see whatever was instantiated in network.

    Any help is greatly appreciated.
    Thanks
     
  2. luke-unity

    luke-unity

    Unity Technologies

    Joined:
    Sep 30, 2020
    Posts:
    306
    Your code looks correct. Spawning an object should cause that object to get automatically be spawned on all later connecting clients as well. Just to be sure, this code is running on the server, right?
     
  3. scarffy

    scarffy

    Joined:
    Jan 15, 2013
    Posts:
    25
    Hello. After some rest, I noticed that I didn't put this code on server side. Now it's running fine.

    Thank you for your time
     
unityunity