Search Unity

Netcode object only spawns and shows on host/server but not on client.

Discussion in 'Netcode for GameObjects' started by MariosAvraam, Mar 13, 2023.

  1. MariosAvraam

    MariosAvraam

    Joined:
    Mar 10, 2023
    Posts:
    1
    I am in the development of a 2d top down environment. I am using netcode for multiplayer, which will only be for a few people.
    I have setup a network manager and added my prefab as a network prefab. My prefab has a network object component attached to it.
    I have setup buttons, so that when I build and run the game I can choose between a server, host and client. I have the host on the main environment and the client on the new window that pops up.
    My issue is that when my object spawns on the server side, it does not spawn on the client side as well.
    My code looks like this.
    Can someone help me?
     

    Attached Files:

  2. afavar

    afavar

    Joined:
    Jul 17, 2013
    Posts:
    68
    Only the server/host can spawn network objects. If you want your client to spawn an object, you need to call a ServerRpc to tell the server spawn the object. Also, it is not required but for player object, you can use the SpawnAsPlayerObject method to acces them easier in the future. (Each client can only have one player object.)
     
    RikuTheFuffs likes this.
  3. cidolfas2015

    cidolfas2015

    Joined:
    Sep 27, 2015
    Posts:
    87
    do you have an example of this method? I have an object that spawns fine host/play but not when I play on a remote server. I'm assuming I need to spawn it on the server?