Search Unity

[UNET] Spawn existing network GameObjects on newly connected client

Discussion in 'UNet' started by Linearch, Jan 24, 2016.

  1. Linearch

    Linearch

    Joined:
    Apr 1, 2015
    Posts:
    33
    I'm trying to do what the title says.

    Let's say I have started the game. Have some clients connected and some networked objects spawned. All's going good. Then a new client joins. He got his new player GameObject and the ownership, but all networked objects that have existed before that new client joined doesn't spawn on the new client. Why? How can I achieve this? NetworkServer.SpawnObjects() doesn't help.

    Thanks.
     
  2. DRRosen3

    DRRosen3

    Joined:
    Jan 30, 2014
    Posts:
    683
    You're doing something wrong. I'm not sure what, but when a client connects to a host, the state of ALL objects with a NetworkIdentity component is relayed to the client. So objects that need to be spawned are spawned.
     
  3. Linearch

    Linearch

    Joined:
    Apr 1, 2015
    Posts:
    33
    Hmm. I'm so lost here, lol. Not sure what I'm doing wrong. I override some methods but also call the base in it, except for OnClientSceneChanged since there will be error about ready stuff, and for OnServerAddPlayer since it would spawn player twice if I don't.

    I'm currently away right now. I'll post the script later, but it's so messy.
     
  4. Linearch

    Linearch

    Joined:
    Apr 1, 2015
    Posts:
    33
    @DRRosen3 Here's the script, derived from NetworkManager.
    I still have no idea what am I doing wrong.

    I have commented out my temporary fix in the script.

    It is trying to relay the states, but the client can't process it since the object doesn't exist in the client which just connected AFTER the objects are spawned. Warnings about it keep being spammed on the console log.

    Thanks
     

    Attached Files:

    Last edited: Jan 26, 2016
  5. Linearch

    Linearch

    Joined:
    Apr 1, 2015
    Posts:
    33
    Anyone pls?
    Btw i have put the prefab on the spawnable list. Do i still need to register it using RegisterPrefab?
     
    Last edited: Jan 26, 2016
  6. noahmilam

    noahmilam

    Joined:
    Mar 4, 2015
    Posts:
    4
    Hello, I had a ball that I was trying to do a similar thing to.the ball was created as soon as the server was created in Start(). in order for me to get it to appear when I spawned a new client I unchecked both options on network Identity. that seem to make it appear for all
    upload_2016-4-8_15-33-8.png
     
    Clossius likes this.
  7. recagonlei

    recagonlei

    Joined:
    Feb 27, 2014
    Posts:
    11
    I'm having the same issue here... A tried with both unmarked, but still nothing... Anyone knows how to fix that?
     
  8. Clossius

    Clossius

    Joined:
    Dec 24, 2015
    Posts:
    3
    Unchecked Server Only and it worked! I was trying to figure this out all day!! 20 google searches later I found this. xD @noahmilam