Network prefab list

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?

This is no longer possible in the 1.0.0 version.

Yeah I figured as much, thanks for confirming.

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.

1 Like

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.

1 Like

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

2 Likes

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.

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.

3 Likes

Nope. It has features for soft referenced objects that aren’t loaded until you want them to be.

2 Likes

=> 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?

1 Like