01 — Hello World
TL;DR: Confirms the toolchain works. Subclasses WasmBehaviour, logs via Debug.Log, reads Time.time, and serializes one int across deserialize/serialize cycles. Works in any ObjectContext (Avatar / Prop / World).
Scene setup
Section titled “Scene setup”- One GameObject in your content root.
CCKWasmProjectDescriptoron the content root.HelloWorldscript attached to the GameObject (or added toincludedScriptson the descriptor).
using UnityEngine;using WasmScripting;
public partial class HelloWorld : WasmBehaviour{ public int logEveryNFrames = 60;
[WasmSerialized] private int frames;
void Start() { Debug.Log("HelloWorld: script started."); }
void Update() { frames++; if (frames % logEveryNFrames == 0) { Debug.Log($"HelloWorld: frame {frames}, t={Time.time:F2}s"); } }
void OnDestroy() { Debug.Log("HelloWorld: script stopped."); }}Source file: examples/01_HelloWorld.cs.
What to look for
Section titled “What to look for”- Unity console shows
HelloWorld: script started.once the content loads. - A log line every
logEveryNFrames(default 60 ≈ once per second at 60 fps). - On instance disposal (teleport away, world unload):
HelloWorld: script stopped.
Walkthrough
Section titled “Walkthrough”public int logEveryNFrames = 60;— public field, serialized by default; editable in the Unity inspector.[WasmSerialized] private int frames;— private field, serialized because of the attribute. Survives across build→runtime. If you reset the VM (content reload) the counter resets too.Debug.Log— routed viaCVR-GameFiles/WasmBinder.LinksManual.UnityEngine/DebugLinksManual.csto the Unity/CVR console.Time.time— bound read-only; returns seconds since scene load.
Permission model
Section titled “Permission model”Debug.Log and Time.time are (Any, Any, Any) — no context requirements. HelloWorld works in avatars, props, and worlds.
Extensions to try
Section titled “Extensions to try”- Change
logEveryNFramesin the inspector and confirm rebuild reflects it. - Add
void OnEnable() => Debug.Log("Enabled");andvoid OnDisable() => Debug.Log("Disabled");and watch the enable/disable transitions. - Mark
logEveryNFrames[NonWasmSerialized]and observe that inspector edits no longer persist through build.
Related
Section titled “Related”- Events — what other Unity events you can add.
- Serialization — attribute rules.