#Spawn NetworkObject from AssetBundle
37 messages · Page 1 of 1 (latest)
Instantiate and spawn a generic object that just has a network behaviour with a SyncVar byte that clients can look up in a static dictionary to find the art prefab that should be instantiated as child art. That art prefab will be marked as an addressable and Unity will load that normally through the addressables system.
ty for you fast answer. Would you be able to give me a small example? I'm a bit stuck at the moment.
so I spawn an empty object, set the model name and the asset bundle on the server-side via sync-var, and then I simply set the object in the client. Am I getting this wrong?
Look at the PickupsDropsChilds example, specifically the SceneObject prefab and script
Too much data in the SyncVar - just a byte (or ushort if you have more than 255 models) for clients to look up the prefab in a dictionary.
I need a system similar to the one in GTA, for example, where you can add things yourself and then load them via a code.
I'll take a look at the PickupsDropsChilds example then.
Define "add things yourself"
I'll explain it in more detail. I am planning a game that offers developers a basis for an RP (role-playing game) server. They should be able to decide and change as much as possible themselves.
They should also have the ability to add clothing for the players/pedals, objects, cars, etc. So I thought it would be best to use AssetBundles for this.
You don't mean for clients to add art to the game for others, right?
Depending on which server you connect to, the client checks whether it already has the assets or whether they need an update. When this is done, the game switches to the correct game scene and must then be able to work with the asset bundles
Yes, but only if the stuff comes from the server he wants to play on
If you let players add art to the game they'll upload porn
They just will...the internet is a nasty place
Yes, that's clear, but it's not my problem. I'm just providing the basis for an RP server. I'll try to limit it via the TOS etc. but you can't ban it completely
If all art comes from you, you build and deploy the asset bundles, and the clients fetch them from your CDN
exactly yes, I currently have my own assets download management as the client is universal.
That's fine...your objects just need to be generic with SyncVar to look up an ID in a dictionary, and the prefabs use addressable art
universal means that the client can connect to different servers but only the bundles loaded from the server it connects to. These are always encrypted in the client as a cache so that the client does not always have to download them again
Okay, I'll give it a try. I don't think I've quite understood it yet
What exactly should I look out for in PickupsDropsChilds example?
^
I can see that the GameObjects are already there as a reference. But I don't have them, I only have the names/IDs in the final effect. Or i oversee something?
The prefab refs are just for convenience of the example...you can do Resources.Load in OnStartClient to populate a dictionary
Okay, if I understand correctly. So do I have to create an empty gameobject with a script component which has the identifier for the model via SyncVar and then I spawn the actual prefab?
I don't want to spawn a child object. I have to spawn it as a main object.
you spawn the generic empty object, the SyncVar hook instantiates the art as child of it on clients
Similar for clothes on player...you have a SyncDictionary of byte enum slot for key and value byte/ushort and the handler looks up the value in the static dict to get the art, pulls that from addressables, and instantiates it on the player per the slot (head / torso / etc)
ah okay, i think i understand it. its then the same as i spawn a complete finished prefab with all included
So I spawn the actual prefab in the generic object. but doesn't that cause problems?
differentiate between instantiate and spawn
For drops, you instantiate on server the generic empty object, set the SyncVar, Spawn it. Client invokes the SyncVar hook, looks in static dictionary you populated from Resources.Load for the art prefab (addressable) and locally instantiates that art as child.
For player clothes, you have a SyncDictionary<slot, id> and the handler does the same as the SyncVar above with the id value
okay, i understood that so far. is it the same for cars and players that move? because of the NetworkTransform etc.?
yes - NT would go on the generic object, along with maybe a suitable collider and kinematic rigidbody and player controller as appropriate.
You may have a few different generic objects prefabs for different "generalized" purposes, e.g. car / human / small object / large object / etc.
As long as the root object moves properly, the child art just goes along for the ride