Search Unity

  1. Improved Prefab workflow (includes Nested Prefabs!), 2D isometric Tilemap and more! Get the 2018.3 Beta now.
    Dismiss Notice
  2. The Unity Pro & Visual Studio Professional Bundle gives you the tools you need to develop faster & collaborate more efficiently. Learn more.
    Dismiss Notice
  3. Let us know a bit about your interests, and if you'd like to become more directly involved. Take our survey!
    Dismiss Notice
  4. Improve your Unity skills with a certified instructor in a private, interactive classroom. Watch the overview now.
    Dismiss Notice
  5. Want to see the most recent patch releases? Take a peek at the patch release page.
    Dismiss Notice

Unity Multiplayer [UNET] Spawn existing network GameObjects on newly connected client

Discussion in 'Connected Games' started by Linearch, Jan 24, 2016.

  1. Linearch

    Linearch

    Joined:
    Apr 1, 2015
    Posts:
    25
    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:
    628
    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:
    25
    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:
    25
    @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:
    25
    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