Spawned Shared Assets
Shared Assets are a limited form of
World.SpawnAsset() that enable certain networked behavior very cheaply. The functions
DestroySharedAsset can only be called on the server, and the spawned object will exist on both the server and client. However, these are very much cheaper than networked objects. The object once spawned cannot be modified, like other objects within a static context. The only option parameters available are transform, position, rotation, and scale.
For further optimization of networked objects, look at the dormancy feature which will make games more performant and utilize more networked behavior by only having certain networked objects replicate when needed.
Spawning Shared Assets
Spawned shared assets need to be spawned into a networked Static Context, otherwise, an error will occur if called on a non-networked Static Context or a Static Context that is a descendant of a Client Context or Server Context.
Below is an example of spawning a shared asset using
SpawnSharedAsset, then after 2 seconds it is destroyed using
DestroySharedAsset by passing in the shared asset to destroy.
local ASSET = script:GetCustomProperty("Asset") local STATIC_CONTAINER = script:GetCustomProperty("StaticContainer"):WaitForObject() -- (1) local obj = STATIC_CONTAINER:SpawnSharedAsset(ASSET) -- (2) Task.Wait(2) -- (3) STATIC_CONTAINER:DestroySharedAsset(obj) -- (4)
- Networked Static Context.
- Spawn shared asset and store a reference in the variable
objso it can be destroyed later.
- Wait 2 seconds which pauses the script.
- Destroy the shared asset by passing in the
NetworkContext API | World API | Networking