Skip to content

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).

  • One GameObject in your content root.
  • CCKWasmProjectDescriptor on the content root.
  • HelloWorld script attached to the GameObject (or added to includedScripts on 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.

  • 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.
  • 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 via CVR-GameFiles/WasmBinder.LinksManual.UnityEngine/DebugLinksManual.cs to the Unity/CVR console.
  • Time.time — bound read-only; returns seconds since scene load.

Debug.Log and Time.time are (Any, Any, Any) — no context requirements. HelloWorld works in avatars, props, and worlds.

  • Change logEveryNFrames in the inspector and confirm rebuild reflects it.
  • Add void OnEnable() => Debug.Log("Enabled"); and void OnDisable() => Debug.Log("Disabled"); and watch the enable/disable transitions.
  • Mark logEveryNFrames [NonWasmSerialized] and observe that inspector edits no longer persist through build.