Search Unity

  1. Unity 2019.1 is now released.
    Dismiss Notice

Unity Multiplayer Spawn scene object not found for 1

Discussion in 'Connected Games' started by yongilkim, Jun 13, 2015.

  1. yongilkim

    yongilkim

    Joined:
    Sep 15, 2014
    Posts:
    10
    i have error while loading map on client and network Scene objects deactivated

    i was calling the NetworkServer.SpawnObjects at the end on map load fuction(on server)

    Spawn scene object not found for 1
    UnityEngine.Networking.NetworkIdentity:UNetStaticUpdate()
     
  2. Zullar

    Zullar

    Joined:
    May 21, 2013
    Posts:
    600
    I have this same problem. I have a host and a client. When I switch scenes using ServerChangeScene() the scene objects with NetworkIdentity components are disabled (as they should be). I then set clients to ready after their scenes load. Then on the server I call SpawnObjects() and the disabled scene objects load on the host, but not on the clients.
     
  3. any_user

    any_user

    Joined:
    Oct 19, 2008
    Posts:
    337
    I also have the same problem, but it only happens sometimes, seems pretty random and might depend on the load timing. Unfortunately I couldn't yet reproduce an exact case when it happens.
     
  4. Zullar

    Zullar

    Joined:
    May 21, 2013
    Posts:
    600
    It seems the randomness might be related to if the server loads before client, or if the client loads before server (just a guess). I found a workaround that seemed to help... I force the server to load first.

    On the server call both of these.
    Application.LoadLevel(sceneName);
    NetworkManager.singleton.ServerChangeScene(sceneName);

    Does anybody know why this is happening?
     
    PhilippG and Zebadiah like this.
  5. Zebadiah

    Zebadiah

    Joined:
    Apr 6, 2014
    Posts:
    7
    I was totally convinced this was something I was doing wrong but after reading this thread I'm less sure. For anyone wondering this still seems to be a problem as of 5.2.0f2 and Zullar's fix seems to work.
     
  6. Zullar

    Zullar

    Joined:
    May 21, 2013
    Posts:
    600
    Zebadiah likes this.
  7. Zebadiah

    Zebadiah

    Joined:
    Apr 6, 2014
    Posts:
    7
    Maybe this will help someone else out. I found this comment while trying to solve an unrelated issue but I think it solves this problem as well. In your custom NetworkManager, if you need to have an Awake method for whatever reason, just put

    Code (CSharp):
    1.  
    2. System.Type type = typeof(UnityEngine.Networking.NetworkManager);
    3. var baseMethod = type.GetMethod("Awake", System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.NonPublic);
    4. if (baseMethod != null) baseMethod.Invoke(this, null);
    5.  
    at the top of the Awake method to call Awake on the base class. Normally you would just call base.Awake() but for some reason the unity devs decided to make the NetworkManager's Awake() method private so you have to use reflection like this.
     
  8. sonic220

    sonic220

    Joined:
    Jan 13, 2012
    Posts:
    35
    I spent 1 hour trying to figure this out but I solved it in the most dumb way.
    I removed and readded the network identity component to my prefab

    I did this because I've noticed the Scene ID = 1 field, while all the others where = 0
    Don't know why unity did this change at some point, but F***ed up my project.
     
  9. Nathan78

    Nathan78

    Joined:
    Sep 21, 2014
    Posts:
    1
    I had the same issue. After reading your response I did the same and it worked. Thank you. I know how mine got messed up though. I had in inadvertently dragged my cloned prefab on to the original prefab while in run mode.
     
  10. SaphiBlue

    SaphiBlue

    Joined:
    Apr 18, 2016
    Posts:
    15
    I had exactly the same problem, I had to recreate my network identity component of the player prefab in the online scene..

    But what if I have multiple online Scenes? Like Map1, Map2 or Map3..... do I need 3 differnt Player Prefabs?
    Sounds Like a bug...
     
  11. FREEZX

    FREEZX

    Joined:
    Apr 2, 2013
    Posts:
    60
    Hi everyone,

    I ran into the same issue and got to the following conclusion:
    If the clients change the scene before the server does, the server will try to sync all NetworkIdentity game objects to its clients. If those are just objects on the scene and are not registered as spawnable objects, the sync will fail because it can't spawn the object, which results in this message.
     
    PhilippG likes this.
  12. Telgemannen

    Telgemannen

    Joined:
    Jun 10, 2015
    Posts:
    6
    So guys, what's your conclusions? All I have is a server enter a scene with one (1) networkobject (one object with networkidentity). Since I use serverchangescene in my custom networkmanager, it nicely enough reactivates this object, However, when a client tries to join the server, I get the error "Spawn scene object not found for 1" and I can't seem to wrap my head around it. It seems to happen when it tries to spawn that object (and as sonic220 wrote earlier, the scene id is 1 instead of 0) because after some mixing I managed it to work without serverchangescene, but I still got the error.. I just can't seem to get rid of it...
     
  13. Zullar

    Zullar

    Joined:
    May 21, 2013
    Posts:
    600
    I *think* what is happening (not completely sure). Let me know if this is what is happening.

    Scene1: Has no networked objects. Default scene
    Scene2: Has 1 networked object

    Order of Stuff that Works OK
    Host starts game in Scene1
    Client connects (Client is Scene1)
    Host switches to Scene2.
    Host sends scene change message to client
    Client loads Scene 2
    Host sends "spawn" messages and spawns the object from Scene2
    Object is properly spawned on Client
    ---Everthing works fine---

    Order of Stuff that Fails
    Host starts game in Scene1
    Host switches to Scene 2
    Host "spawns" object from scene 2 (and it loads properly on host)
    Client connects (but client is in scene 1)
    Client receives "spawn" messages for the object in scene 2. But the object doesn't exist because client is still in Scene1
    Host sends scene change message to client
    Client loads Scene 2
    ---The client is in scene 2, but the object failed to spawn because messages are received in incorrect order---


    I'll also add that I've realized that SceneObjects are NOT added to the spawnedObjectList that is automatically maintained for late connecting players. If you have a SceneObject and use DontDestroyOnLoad() and carry that SceneObject to another scene where it doesn't exist... and then connect with a client... the client will not get that object. However if you instantiate & spawn a registered prefab (as opposed to a scene object) then it works fine for late-connecting-players even if they connect to a scene where the object was not generated.
     
  14. csetien

    csetien

    Joined:
    Apr 21, 2016
    Posts:
    3
    I can not delete my network Identity my scripts are dependent on it and I seem to be able to connect to the same room but can not see the other players. I attempted to change the net ID from local to server only and then back to local but all that has done is allow players to join the same game but not see each other. Please help. I am a total noob
     
  15. SweatyChair

    SweatyChair

    Joined:
    Feb 15, 2016
    Posts:
    102
    Spent half day finding the problem until I read this... the scene id became 1!! I just change it back to 0 in inspector debug mode.... how could this happen and where is the scene id used?!?

     
  16. richardboegli

    richardboegli

    Joined:
    Dec 28, 2016
    Posts:
    13
    Yep, had this same problem and used your solution.
    Not sure why, as it was a brand new project.
     
  17. MFKJ

    MFKJ

    Joined:
    May 13, 2015
    Posts:
    188
    hi guys I am getting
    I am loading additive scene through rpc call but as my new scene load its all network identity object becomes disable so i use this line of code in start of my next scene. its showing me this error

    Spawn scene object not found for 1............

    Although it is running fine on server but not on client. please help
     
  18. MFKJ

    MFKJ

    Joined:
    May 13, 2015
    Posts:
    188
    I used this solution, now object is displaying but objects transform is not syncing across network.
     
  19. deLord

    deLord

    Joined:
    Oct 11, 2014
    Posts:
    250
    Can someone clarify what is meant by "scene id" and where I can find that? Do you mean the number that is next to the scene in "Build Settings" (Ctrl-Shift-B)?
    I didn't understand when to remove and readd the NetworkIdentity component and what the scene ID has to do with it.
     
    vincewins likes this.
  20. MFKJ

    MFKJ

    Joined:
    May 13, 2015
    Posts:
    188
    Use debug mode in inspector, you will get scene id in network identity/behaviour.(I Guess)
     
    deLord likes this.
  21. deLord

    deLord

    Joined:
    Oct 11, 2014
    Posts:
    250
    for me, I get all sorts of scene IDs ô.O
    there are more than 3 different sceneIds and all those objects are disabled from the beginning. Even a canvas that does nothing except having a NetworkIdentity and NetworkTransform attached to it. It only exists on both server and client if I host from the Editor. Does this make sense?
     
  22. MFKJ

    MFKJ

    Joined:
    May 13, 2015
    Posts:
    188
    I have also get hanged in network identity objects active/deactive. As i tried to load an additive scene, it's all object become disabled. You should write some code to enable it again.
    https://docs.unity3d.com/Manual/UNetSpawning.html
     
  23. AntonQvarfordt

    AntonQvarfordt

    Joined:
    Mar 14, 2013
    Posts:
    11
    I think that the reason for this is that Unity Networking wants GameObjects with a NetworkIdentity component attached to be set as registered prefab in the network manager and get spawned in at runtime by the server.

    The reason for this being that if you save a NetworkIdentity GameObject to a scene that all parties loading the game in multiplayer game individually loads in then you have as many instances of the GameObject as there are number of players and it becomes hard to synchronize. Hence they want it registered as an identity that the server controls and spawns so there can be an actual authority on the state of that object.

    I'm not an expert but that is my understanding.
     
  24. lucasmontec

    lucasmontec

    Joined:
    Apr 7, 2015
    Posts:
    85
    Last edited: Mar 9, 2017
  25. helgewt

    helgewt

    Joined:
    Jul 21, 2015
    Posts:
    12
    In my case this was caused by the standard implementation of OnClientConnect triggering ClienScene.Ready if onlineScene is left unconfigured. This results in the client receiving spawn message before the new scene has loaded.

    See this post for a possible workaround.
     
  26. dgoyette

    dgoyette

    Joined:
    Jul 1, 2016
    Posts:
    1,665
    This happened to me, and it seems like the reason was that instead of assigning my prefab to my Network Manager's "Player Prefab", I had dragged the "player" object that I had in my scene. Although that player was an instance of my player prefab, it wasn't the prefab from my "Resources" folder.
     
    Arcelus likes this.
  27. rob_vld

    rob_vld

    Joined:
    Jul 9, 2013
    Posts:
    149
    So... i just picked up on this NetworkManager stuff... then ran into OP's problem, i simply cannot get it to work... assuming i did everything right, this is a critical issue...

    now this thread started somewhere mid 2015... how can this still be a thing; is Unity no longer taking its networking solution serious?

    what is the current standing on this, should i abandon it?
    i really would like to use it though...
     
  28. Dreamer

    Dreamer

    Joined:
    Mar 8, 2011
    Posts:
    64
    I'm having exactly the same issue. This error just jump out of nowhere.
     
  29. rob_vld

    rob_vld

    Joined:
    Jul 9, 2013
    Posts:
    149
    After some help, i have been made aware of my mistake... there is no longer an issue for me...
     
  30. SH-Z

    SH-Z

    Joined:
    Oct 23, 2017
    Posts:
    1
    now,it is an issue for me ...can you tell me how to solve it?I'm very upset about that.
     
  31. Kylotan

    Kylotan

    Joined:
    Feb 17, 2011
    Posts:
    192
    Just hit this very same issue myself. It was the same problem as mentioned earlier in the thread - one of the NetworkIdentity components had ended up with a Scene ID of 1 instead of 0, and even though that prefab was not in the scene I was playing, it still broke everything.
     
  32. HinxLai

    HinxLai

    Joined:
    Dec 31, 2017
    Posts:
    4
    My problem resolved! I found out that I do active an network object(Object Pool Manager ) in a client when netwotkManager was not ready, the networkidentity use anothor Network Channel , So cause the error while an Rpc cmd working.
    Ckeck it out.
     
  33. razavidn

    razavidn

    Joined:
    Dec 23, 2017
    Posts:
    2
    So, I spent about two days on this problem looking at every possible solution recommended here and elsewhere. My solution was ultimately different, so for anyone who stumbles on this, here was my issue:

    I had a networkID component attached to a game object that didn't need it.

    More specifically, I had an object that I had originally attached a NetworkBehaviour to, along with the required network ID. I then decided I didn't need the script to be a NetworkBehaviour, and changed it to a MonoBehaviour, but accidentally left the network ID component on the object.

    This object was created in my lobby scene, and was set as the child of a parent that had "Don't Destroy On Load Set." (Specifically, the parent was my NetworkLobbyManager, for reasons I don't really need to get into here). When the scene changed over, this apparently caused Armageddon. Removing the networkID component from the object solved the problem.
     
    jethrogillgren likes this.
  34. llluuo_

    llluuo_

    Joined:
    Apr 20, 2017
    Posts:
    6
    I find out that we should put the prefab in the hierarchy. You should drag the prefab from Project to network manager.
     
    AJAW likes this.
  35. pjcferreira

    pjcferreira

    Joined:
    Jul 2, 2016
    Posts:
    2
    In my case this error occurred when the online scene in the network manager was null, for me this wasn't a problem because I was setting this value in code.
     
    Zullar likes this.
  36. jethrogillgren

    jethrogillgren

    Joined:
    Jan 11, 2017
    Posts:
    28
    Found a new possible cause for this:
    Disabling (ie tick the box in the inspector to turn it off) a Scene Networked Object.
     
  37. Prrrpl

    Prrrpl

    Joined:
    Dec 6, 2016
    Posts:
    3
    Hi everyone,

    Since this is the first result on Google when looking for the error: 'Spawn scene object not found for 1 UnityEngine.Networking.NetworkIdentity:UNetStaticUpdate()' I thought I'd also post the solution I found which fixed the problem for me.

    I have a Network Manager GameObject with the Network Manager Component attached. In the Network Manager Component, there is a section called 'Spawn Info'. At the 'Player Prefab' input slot, I added my Player GameObject. However my 'Player' GameObject was NOT a Prefab and this appearently caused the error.

    To fix it, I simply converted my 'Player' Object to a Prefab and re-inserted it into the Player Prefab slot in the Network Manager component of my Network Manager GameObject.

    I came to this solution when I found out it is caused because the Player Prefab input field accepts non-prefabs and that this is registered as an issue in Unity: https://issuetracker.unity3d.com/is...object-with-networkidentity-instead-of-prefab

    Hope this helps others who tried the solutions offered above (re-adding the Network ID component for example) that did not help them fix the problem.
     
  38. atlas-amfistomos

    atlas-amfistomos

    Joined:
    Jun 9, 2016
    Posts:
    2
    You may want to make your game object a prefab and assign the prefab to the network manager's 'Player Prefab'
     
    FuriousEX likes this.
  39. BloodHound_PL

    BloodHound_PL

    Joined:
    May 12, 2016
    Posts:
    2
    Hello everyone,

    I've been facing this issue several times over last two years when occasionally working on some simple multiplayer projects.

    What I've noticed this time is that Unity seems to confuse sceneIDs when persistent Network Identity objects are on various scenes, even if these scenes are loaded roughly at the same time.

    Placing all persistent Network Identity objects on the same scene fixed the problem for me. This scene is originally unloaded at runtime and loads only if I press Start Game button in my main menu. No multiplayer logic is present before. All I needed to change in my design was to make my singleton-manager get missing cross-scene references to moved network objects by waiting for them through Coroutines.

    This issue concerned persistent objects only, spawned objects never behaved in a wrong way for me.

    As to resetting Network Identity, it never worked for me and I noticed everytime I loaded new scene, all existing ID's were reset automatically, even If earlier I forced their values programatically through NetworkIdentity.ForceSceneId(int newSceneId).
     
    Last edited: May 23, 2019
  40. Zullar

    Zullar

    Joined:
    May 21, 2013
    Posts:
    600
    I think UNET is not really being supported anymore. It might be best to move on to another networking package before you invest too much time.
     
    Joe-Censored likes this.
  41. Joe-Censored

    Joe-Censored

    Joined:
    Mar 26, 2013
    Posts:
    5,428
    From what I've read, Mirror has a proper fix for this issue. Otherwise I'd drop Unet because Unity is not going to be fixing any of these long standing bugs in Unet.