Search Unity

  1. Unity 6 Preview is now available. To find out what's new, have a look at our Unity 6 Preview blog post.
    Dismiss Notice
  2. Unity is excited to announce that we will be collaborating with TheXPlace for a summer game jam from June 13 - June 19. Learn more.
    Dismiss Notice

Question about registering Network Prefabs

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

  1. Kyperr

    Kyperr

    Joined:
    Jul 15, 2016
    Posts:
    32
    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

    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:
    32
    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:
    27
    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

    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.