#Spawn NetworkObject from AssetBundle

37 messages · Page 1 of 1 (latest)

halcyon meadow
#

Hey, what do I need to consider when spawning a prefab from an AssetBundle on the server side? What do I need to do on the client?

hot arrow
halcyon meadow
#

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?

hot arrow
#

Look at the PickupsDropsChilds example, specifically the SceneObject prefab and script

hot arrow
halcyon meadow
#

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.

halcyon meadow
# hot arrow 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.

hot arrow
#

You don't mean for clients to add art to the game for others, right?

halcyon meadow
#

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

hot arrow
#

If you let players add art to the game they'll upload porn

#

They just will...the internet is a nasty place

halcyon meadow
#

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

hot arrow
#

If all art comes from you, you build and deploy the asset bundles, and the clients fetch them from your CDN

halcyon meadow
#

exactly yes, I currently have my own assets download management as the client is universal.

hot arrow
#

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

halcyon meadow
#

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

halcyon meadow
#

What exactly should I look out for in PickupsDropsChilds example?

halcyon meadow
# hot arrow ^

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?

hot arrow
halcyon meadow
#

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?

halcyon meadow
hot arrow
#

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)

halcyon meadow
#

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?

hot arrow
#

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

halcyon meadow
#

okay, i understood that so far. is it the same for cars and players that move? because of the NetworkTransform etc.?

hot arrow
#

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