Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.

Network prefab list

Discussion in 'Netcode for GameObjects' started by cerestorm, Nov 17, 2021.

  1. cerestorm

    cerestorm

    Joined:
    Apr 16, 2020
    Posts:
    237
    I haven't found a way of getting a list of network prefabs, the ones you add to the NetworkPrefabs list in the editor for NetworkManager, is it possible?
     
  2. luke-unity

    luke-unity

    Unity Technologies

    Joined:
    Sep 30, 2020
    Posts:
    306
    This is no longer possible in the 1.0.0 version.
     
  3. cerestorm

    cerestorm

    Joined:
    Apr 16, 2020
    Posts:
    237
    Yeah I figured as much, thanks for confirming.
     
  4. unity_OrWd8VhKj9gEzg

    unity_OrWd8VhKj9gEzg

    Joined:
    Sep 29, 2018
    Posts:
    1
    That's a bit of a shame, I'd have liked to write tests to ensure certain objects are present there without having to spin up a server and client and just seeing if they spawn right.
     
  5. MaskedMouse

    MaskedMouse

    Joined:
    Jul 8, 2014
    Posts:
    872
    personally I find the whole
    NetworkedPrefabs
    list inconvenient. Not only does it load everything into memory but you might end up not even using some of them at all.

    I'm creating a multiplayer tower defense game. First time I'm creating a multiplayer game. Normally I'd just use Addressables to load in prefabs whenever I need them. But with multiplayer they all need to be in the networked prefab list. If I were to create different races with X amount of different towers, I would have a long list of
    NetworkedPrefabs
    .

    Why is it necessary to have a networked prefab list? What is its purpose under the hood?
    It kind of feels like an odd way of
    Resources.Load
    for the
    NetworkingManager
    .
     
  6. cosminunity

    cosminunity

    Unity Technologies

    Joined:
    Mar 4, 2021
    Posts:
    14
    Hey @MaskedMouse,

    I can understand having a NetworkedPrefabs list where you need to pre-register your prefabs is inconvenient, I am very sorry for that. I wanted to let you know that we are well aware of it. This has been a limitation of the SDK from the start, due to how synchronization works currently, we really need to ensure that both server and client have exactly the same NetworkObject prefabs registered (at the same time) so that we can replicate them, otherwise, the client wouldn't understand what is meant to be spawned/despawned/etc and some ugly errors would pop-out.

    Unfortunately, we are not able to drastically change how the Registration works as it touches quite a lot of features in the SDK and will likely destabilize it in the current release, for future (major) releases, however, this is something we will carefully take under consideration.

    Additionally, I also wanted to point out that I and my team have a PR on our GitHub that adds support for Addressables (in a similar manner where things would get preloaded) and we made the NetworkPrefabs list accessible from outside. Whilst, this still won't solve your issue, it will at least help a bit with your Addressables workflows.

    P.S.: Here is a link to the PR mentioned above.

    Greetings,
    Cosmin Bararu
     
    hippocoder likes this.
  7. MaskedMouse

    MaskedMouse

    Joined:
    Jul 8, 2014
    Posts:
    872
    I get that you'd need the exact same prefab on server and client. And I get that you'd need some kind of reference to the prefab for runtime use for both client and server. But I guess this is just based on a limitation of how Unity loads assets. Resources.Load was never a good idea and anything you reference in the scene is loaded into memory. Sadly prefabs too. Which is where Addressables comes in, you load it when you need it kind of reference.

    So even with Addressables, things are still being preloaded? That would kind of beat the purpose of having addressables. Also if the loaded addressable asset is a different version than the server's version you'd still have the same issue. Where one would have a different version of the prefab than the server.

    I had kind of hoped and still do that preloading assets into memory won't be necessary in the future. The reference to the prefab is there, but when it is not needed, don't load it into memory.
    After reading the PR comments further it's the API that has to be refactored a lot in order to load assets asynchronous. Which won't be done in this version. Well that's kind of a pity, but I hope that this will still be a feature in the future.
     
    Last edited: Mar 8, 2022
  8. OldKing_Wang

    OldKing_Wang

    Joined:
    Jan 25, 2015
    Posts:
    38
    Hi

    is there a way i can add Network Prefab in Editor Mode via script.

    my scene is complete generate by code . so i need register all the game item (nearly 50+) to network prefab and
    Spawn them when the level generated.

    but i check NetworkManger.cs the Network Prefab is store in NetworkConfig.NetworkPrefabs (internal)

    there is no way i can write that list.

    --------

    what i want do is write a editor script , scan a specific folder in my project. and register all the prefab under that folder to Network Prefab.
     
    ElliotB likes this.
  9. hippocoder

    hippocoder

    Digital Ape Moderator

    Joined:
    Apr 11, 2010
    Posts:
    29,107
    Nope. It has features for soft referenced objects that aren't loaded until you want them to be.
     
    nico_st_29 and MaskedMouse like this.
  10. nico_st_29

    nico_st_29

    Joined:
    Mar 14, 2020
    Posts:
    68
    => Is the NetworkedPrefabs list of the NetworkManager actually accessible from outside? Or is that only going to be available once the addressables PR gets merged?
     
unityunity