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.

Question about registering Network Prefabs

Discussion in 'Netcode for GameObjects' started by Kyperr, Jan 13, 2022.

  1. Kyperr

    Kyperr

    Joined:
    Jul 15, 2016
    Posts:
    31
    My list on the Network Manager is growing quite large. The NetworkPrefabs list doesn't seem to be accessible, conventionally through code and I haven't seen anyone automate registering prefabs.

    I considered extending NetworkPrefabs to register prefabs with a certain tag or script or read from a ScriptableObject DB that automatically registers prefabs. I am wondering if there is a reason to not do this. It seems like the kind of thing that would have been done before or even built in.

    Perhaps I am missing something. Is the best out-of-the-box solution really to drag and drop items into the editor?
     
  2. luke-unity

    luke-unity

    Unity Technologies

    Joined:
    Sep 30, 2020
    Posts:
    306
    It's unfortunately currently the only way to do it. Anything else would need modification of the source code.
     
  3. Kyperr

    Kyperr

    Joined:
    Jul 15, 2016
    Posts:
    31
    Alright. That's what I was afraid of. As a result, I've adopted a model of using super generalized prefab such as NetworkProjectile that, OnNetworkSpawn, fills out the rest of the information based on ID. More infrastructure code, but with something like a bullet-he'll that has dozens or hundreds of projectiles that all have different behaviors, it's much better to simply register one prefab.
     
  4. TheCaveOfWonders

    TheCaveOfWonders

    Joined:
    Mar 2, 2014
    Posts:
    19
    Are there any plans to change this? I'm also running into a similar situation as the op and wouldn't want to invest in some workaround if Unity is planning to change this at some point in the near future.
     
  5. luke-unity

    luke-unity

    Unity Technologies

    Joined:
    Sep 30, 2020
    Posts:
    306
    Yes we had a discussion about this recently and we'll try to figure out a better solution.
     
  6. TheSleepyPenguin

    TheSleepyPenguin

    Joined:
    Nov 9, 2013
    Posts:
    5
    I'm building an app that loads prefabs from asset bundles at runtime, so I CAN'T add them in the editor. Looks like I'll need to find another networking solution until this is fixed. :-(
     
    itsugamer and unnanego like this.