Prop Context Examples
TL;DR: A prop script runs on every client that sees the prop. Writes inside the prop’s own hierarchy are permitted; writes to world, avatars, or other props are not. Prop destruction comes for free via the CVR API, but only a world script may call it. State resets when the prop despawns unless you persist it yourself.
What prop scripts can do
Section titled “What prop scripts can do”- Read and write their own hierarchy.
- Receive Unity lifecycle + physics events,
OnPropSpawned,OnPropDespawned. - Respond to trigger/collision events on their own colliders.
- Identify the spawner via
Prop.GetCurrentProp().GetSpawner()and compare againstLocalPlayer.PlayerObject(thoughLocalPlayer.*is world-only — so for avatar/prop, compare against the inboundPlayerarg in game events instead). - Send and receive network messages via
WasmScripting.Networking. - Read
CVR.CVRInput.*(for input-reactive widgets when the local player is the spawner).
What prop scripts cannot do
Section titled “What prop scripts cannot do”- Call
LocalPlayer.*— world-only. Use game-eventPlayerargs to identify users. - Touch
FileStorage/WorldPermissions/WorldSettings— world-only. - Call
CVR_Prop_Destroyon themselves or any other prop — that binding is(World, Any, —). A prop wanting to self-destruct networks a “destroy me” signal to a world script that callsDestroy(). - Mutate transforms outside the prop’s root.
- Compare
Playerargs, notLocalPlayer. Game events likeOnPlayerTriggerEnter(Player)give you the interacting player directly; avatar/prop scripts should use that, sinceLocalPlayer.PlayerObjectis world-only. - Use
[WasmSerialized]for per-prop state you want to survive inspector → runtime serialization. - Cache hierarchy lookups — resolving
prop.GetRootTransform()orprop.GetRootObject()each frame costs a host call. Cache inStart. - Networked state should flow through the spawner. The spawner is authoritative; other clients apply incoming messages.
Don’ts
Section titled “Don’ts”- Don’t assume prop state persists across despawns. When a prop despawns and respawns, you get a fresh VM. If the state has to survive, the spawner’s client must save it via a world-scoped escape hatch (another world script writing to
FileStoragewith the prop’s content ID as the filename). - Don’t expect
LocalPlayer.*calls to work — they throwWasmAccessDeniedException. - Don’t call
prop.Destroy()— needs a world script. Signal via network, have the world script actually destroy. - Don’t subscribe to
OnPropSpawnedthinking it’ll tell you “I just spawned” — it fires on all observers when any prop (yours or someone else’s) spawns. UseStartfor “I just came alive”. - Don’t write
[DefaultExecutionOrder]expecting it to order against Unity — it only orders among WasmBehaviours in the same VM.
Included in this book
Section titled “Included in this book”- Dice Roller — a 6-sided die you shake; owner rolls, everyone sees the same result; fully prop-scoped.
Related
Section titled “Related”- Permissions — the three-axis model.
- Events → Prop events — full signatures.
- Networking — owner-authoritative patterns.
- CVR Host Functions → Prop — exact binder names.