Search Unity

Unexpected objects getting spawned

Discussion in 'Multiplayer' started by Vinny-the-true, Mar 20, 2018.

  1. Vinny-the-true

    Vinny-the-true

    Joined:
    Nov 28, 2016
    Posts:
    10
    Hi,
    I'm currently working on a multiplayer platformer in which in each level there is a scoring prefab for each player.
    These objects are sometimes getting spawned right after the StartHost(). Despite the fact the game is not inside a level at this point.
    What happens is that I can see these 4 (it's a game playable up to 4 players) prefabs with their NetIDs in the list of Server object in the NetworkManager inspector.
    If I setup a breakpoint in any method of any script that is hold on these prefabs, nothing gets ever called. And clicking on them in the editor won't show up any object instanciated, neither in the current scene nor in the "dontdestroyonload" part. That being probably because they shouldn't exist in the first place I guess !

    On top of that, this behaviour is not systematic, sometimes it goes well, the 4 objects appearing when they're supposed to, when you launch a level.
    I am not sure what the impact of these objects is, but I get warnings on network messages for the very netID of these objects, so I would guess there *is* an impact.

    How can I only begin to debug and find out why and how these objects get spawned (even though, they might not really get spawned, because they don't appear in client object lists...) ? I am clueless about how to begin to fix this situation and would greatly appreciate any help from there..

    Thanks
     
  2. Joe-Censored

    Joe-Censored

    Joined:
    Mar 26, 2013
    Posts:
    11,847
    Can you post the script where you are spawning these objects?
     
  3. Vinny-the-true

    Vinny-the-true

    Joined:
    Nov 28, 2016
    Posts:
    10
    Well... Thing is I am not... The objects are positionned in the level scenes, so UNet is spawning them automatically like any other NetworkIdentity gameObject when present and active when the scene loads. And this is the only way I expect these 4 objects to be spawned.
    And when the connection is established, I see the 4 objects although we're in a sort of lobby scene, and no level scene is loaded at all.
     
  4. Joe-Censored

    Joe-Censored

    Joined:
    Mar 26, 2013
    Posts:
    11,847
    Are you sure that server isn't running the wrong scene, or that the level scene wasn't additively loaded by either the server or client?
     
  5. Vinny-the-true

    Vinny-the-true

    Joined:
    Nov 28, 2016
    Posts:
    10
    Pretty much yes. If I run the server from the Unity Editor, I can see only the scene I'm expecting to, as well as my bunch of "dontDestroyOnLoad" objects. And everything seems fine if I look at the object hierarchy. Especially, there is no instance of the 4 objects mis-spawned anywhere in it (this is why clicking on the object in the server object list doesn't select anything in the hierarchy, as it should when the objects actually exist)

    I may add that I can see the problem even before any client connects, so it's 100% server (host to be precise) related I would say.
     
  6. Joe-Censored

    Joe-Censored

    Joined:
    Mar 26, 2013
    Posts:
    11,847
    If these are scene objects, then somehow you must be loading the scene they are from. I can't explain why that would be happening though. I'd run a test by unchecking the scene these objects are from in your build settings and see if they still appear, or if you get any errors.