Porting scripts: the same idea, spelled differently¶
Bringing a script over from plain Unity — or rebuilding something you made on another platform? The capability you're reaching for almost always exists here, under a different spelling. Work through this table before concluding something is missing: the most common porting mistake isn't a missing API, it's twenty minutes spent building a workaround for a feature that has a name you didn't search for.
The translation table¶
| You're looking for | The NexusScript answer |
|---|---|
Instantiate(prefab) / GameObject.Instantiate |
Object.Instantiate(prefab) — rate‑limited, and a script may only Destroy objects it created. For high‑churn spawners (projectiles, pickups) pre‑place a pool of children and toggle SetActive |
renderer.material.SetColor(...) on one object |
renderer.material aliases the shared material — recoloring one copy recolors them all. Per‑instance color is renderer.SetColor(c). See Rendering |
GetComponent<Camera>() |
blocked by design — assign a serialized public Camera field in the Inspector instead |
protected override void OnEnable() |
write a plain void OnEnable() (it isn't virtual) — and put one‑time setup in Start() |
Writing Physics.gravity or Time.timeScale |
read‑only for a world; per‑player gravity is Player.SetGravity(playerId, g) |
An inspector T[] / List<T> field |
array fields arrive Null silently — use ONE container reference and gather with GetComponentsInChildren<T>() in Start(). See Gotchas |
Application.platform ("am I in VR?") |
VR.IsPresent() |
| "Send a network event" to everyone / to one player | [ServerRpc]/[ClientRpc] methods + Network.SendServerRpc / SendClientRpc / SendClientRpcToTarget. See Networking |
| "Save player progress between visits" | your own backend via server‑side HTTP.* with stored credentials, keyed by Player.GetUserId. Storage.* is session memory only — a world instance is ephemeral, so there is deliberately no durable platform store |
| "Download text or an image at runtime" | server‑side HTTP.* triggered from a [ServerRpc]; runtime images via SpriteRegistry.* / AI.GenerateImageOnto |
| "Wire a UI Button to my script" | btn.AddClickListener("MethodName") in Start(), or point the Button's onClick at NexusComponent.InvokeByName. See UI |
| A seat / vehicle with driver input | the Station component + Station.* (GetThrottle/GetSteer/… + GetButton) |
| "A player entered my zone" | OnTriggerEnter(Collider) + Collider.CompareTag / Player.IdOf. See Physics |
| A held "use" action (draw a bow, hold a horn) | the OnUseDown() / OnUseUp() reserved callbacks on the interactable; Controls.* for analog pressure or inputs not aimed at an object. See Interactables API |
| A clock every player agrees on | Network.GetServerTime() — the server's UTC as Unix seconds, the same value on the server and every client (per‑client Time.* values differ). Store a start time in a synced field once and every peer computes elapsed. See Networking |
When the name really isn't anywhere¶
Search the API Reference by concept, not by the name you remember — the reference lists every callable group and member. If the concept is genuinely absent, one of two things is true:
- It's absent on purpose. The reference ends with "Not part of the surface — by design" — each entry there names the sanctioned alternative. Use the alternative; a workaround that needs anything outside the sandbox cannot ship in a world.
- It's a gap. Then we want it reported, not worked around — see Gotchas: a documented call that seems to do nothing.