Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Bug Disable Scene Management with In Scene NetworkObjects

Discussion in 'Netcode for GameObjects' started by Salja, Jun 7, 2022.

  1. Salja

    Salja

    Joined:
    Mar 23, 2017
    Posts:
    353
    Hello everyone, maybe someone can help me here. I would like to handle my scenes myself and have therefore switched off the scene management in the NetworkManager. But I need NetworkObjects in the Scene, so I created a prefab from the Object and registered it in the NetworkManager list. I still get the error [Netcode] Failed to create object locally. [globalObjectIdHash=1067131831]. NetworkPrefab could not be found. Is the prefab registered with NetworkManager?

     
  2. cerestorm

    cerestorm

    Joined:
    Apr 16, 2020
    Posts:
    653
    I tried the above and also get the same result. I'm a bit suspicious of pre-existing network objects as I'm not convinced on how they're meant to link with the prefab in the NetworkManager list.

    I did get it to work by overriding the Lobby prefab in the NetworkManager list and dragging the scene's Lobby object into the Overriding Prefab slot. I don't know what you'd do with multiples of the same object in the scene but with only one Lobby object this appears to work fine.
     
  3. Salja

    Salja

    Joined:
    Mar 23, 2017
    Posts:
    353
    Yes i try to override with hash too and works but i think this is not the right way ?
     
  4. CosmoM

    CosmoM

    Joined:
    Oct 31, 2015
    Posts:
    204
    If you disable scene management in the NetworkManager then you cannot have pre-existing NetworkObjects in the scene. In that case, you will have to spawn them in yourself as soon as the scene loads.
     
  5. cerestorm

    cerestorm

    Joined:
    Apr 16, 2020
    Posts:
    653
    I agree pretty much. You could in theory have pre-existing objects in the server scene but you'd still need to control when and to whom they're spawned to so I would treat them like other network objects for consistency.

    If it's any help here's the basics I use for creating the lobby in my project with scene management disabled. After network start the server has only one scene were it handles client events and runs timer routines. The lobby object is instantiated and spawned in the server scene with visibility disabled. When a client connects and enters the client lobby scene the lobby is made visible to that client.
     
  6. Salja

    Salja

    Joined:
    Mar 23, 2017
    Posts:
    353
    OK maybe I'm thinking too complicated ? Maybe I should explain what I intend to do and maybe someone can point me in the right direction how best to implement it !

    My game is an offline story based RPG, I wanted to add a multiplayer option, the whole thing should work like this.Someone creates a host for his friends. A total of 5 people should be able to play together. In the main menu there should always be a display of who is currently connected.

    i don't want to have a ready check, but everyone can connect when they want, everyone should also join the game when they want, so i turned off the scene management.

    I have already implemented the display in the main menu. No player is spawned, but only entered in the list which player is connected, as an example, I would like to go into the game now, and maybe the other people in the main menu would still like to make their settings.

    As soon as I'm in the game world, the player should be spawned, in my offline game I already have a spawn manager that takes over this task, so I thought I could use the same one but as a network behavior this would be in the scene and it works yes unfortunately not.

    So what would be the best implementation to do something like this?

    i know the SpawnManager is not yet setup for network i was think before to use this as in scene Networkbehavior but this is not working



    Screenshot_1.png

    Screenshot_2.png
     
  7. cerestorm

    cerestorm

    Joined:
    Apr 16, 2020
    Posts:
    653
    Converting a single player game to multiplayer can be quite a challenge, you'll want a good grounding in multiplayer concepts before you start. That should give you a good idea on the magnitude of the task ahead.

    If you want to allow for connected players to be in different scenes you'll be adding a lot more complexity on top of an already difficult task, I would try if possible to let Netcode handle the scene management.