Spawned object is null.

Hi. Executing the code below on the host side works fine (mCume != null), however, on the client side it always ends with mCume = null. Am i missing something?

    public GameObject cubePrefab;    
    public GameObject mCume;

    void Update()
    {
        if (isLocalPlayer)
        {   
            CmdSpawnCube();
        }
    }
    [Command]
    void CmdSpawnCube()
    {
        mCume = (GameObject)Instantiate(cubePrefab);
        NetworkServer.Spawn(mCume);
    }

Thank you!

You’re probably not setting the gameobject reference on your clients, as [Command] functions only run on the server / host end of the game.Try using a rpc to reference the instantiated gameobject on all clients as well.

I hope I helped you out with this!

Hi. From what i understand:

  1. Instantiate the object - on the server.
  2. Spawn this object - on the server.
  3. With object’s NetworkInstanceId we get the GameObject using the ClientScene.FindLocalObject function - on the client (ClientRpc).

Is this the correct way?