Available Attributes
TL;DR: A small set of CVR attributes ([WasmSerialized], [NonWasmSerialized], [ExternallyVisible], [WasmRuntimeInitializeOnLoadMethod]) plus the standard Unity editor attributes work inside WASM scripts. The CVR-specific ones drive serialization and UnityEvent exposure; Unity editor attributes are preserved for inspector UX but stripped from the runtime module unless opted in.
CVR attributes
Section titled “CVR attributes”[WasmSerialized]
Section titled “[WasmSerialized]”Source: CVR.CCK.Wasm/Scripting/Attributes/SerializationAttributes.cs.
Apply to:
- Fields — opts a private field into serialization. Public fields are already serialized by default.
- Classes — required on custom (non-Unity, non-primitive) classes whose fields you want serialized. Without it the outer serializer visits a reference but does not descend into the class’s fields.
[WasmSerialized]public class Checkpoint{ public int index; public Vector3 position;}
public partial class Track : WasmBehaviour{ public Checkpoint[] checkpoints; // deep serialized because Checkpoint carries the attribute [WasmSerialized] private int privateState; // private field opted in}[NonWasmSerialized]
Section titled “[NonWasmSerialized]”Source: CVR.CCK.Wasm/Scripting/Attributes/SerializationAttributes.cs.
Apply to public fields to exclude them from serialization (transient UI / debug state).
[NonWasmSerialized] public float debugTimer; // editable in inspector but not baked[ExternallyVisible]
Section titled “[ExternallyVisible]”Source: CVR.CCK.Wasm/Scripting/Attributes/ExternallyVisibleAttribute.cs. Attribute target: methods.
Required on any method the host invokes by name — UnityEvent persistent listeners (Button.onClick, Toggle.onValueChanged, Slider.onValueChanged, animation events), CVRInteractable / CVRPointer method calls, and any direct TriggerScriptEvent(name) from host code. Without it, the CCK build processor rewires the listener to TriggerScriptEvent("YourMethod") as usual, but the guest-side dispatcher has no entry for the name, so the call silently no-ops at runtime — buttons appear wired in the inspector but do nothing when pressed.
public partial class Panel : WasmBehaviour{ [ExternallyVisible] public void OnButtonClicked() { /* targeted from Button.onClick in the inspector */ }}Not needed for: Unity lifecycle methods (Start, Update, OnDestroy, OnTrigger*, OnCollision*), CVR game events (OnPlayerJoined, OnPlayerTriggerEnter, OnInstanceOwnerChange, OnWorldPermissionsChanged, …), delegate subscriptions (Networking.OnReceiveMessage += ...), and direct same-VM method calls between behaviours.
See Unity Events Rewiring for the dispatch mechanism end-to-end.
[WasmRuntimeInitializeOnLoadMethod]
Section titled “[WasmRuntimeInitializeOnLoadMethod]”Source: CVR.CCK.Wasm/Scripting/Attributes/WasmRuntimeInitializeOnLoadMethod.cs. Attribute target: static methods.
Placeholder attribute, currently unused by the build pipeline. Reserved for “run on module load” semantics analogous to Unity’s [RuntimeInitializeOnLoadMethod]. Don’t rely on it firing anything in the current CCK.
Standard Unity attributes (serialization-related)
Section titled “Standard Unity attributes (serialization-related)”All of these work as you’d expect on a WasmBehaviour subclass:
| Attribute | Purpose |
|---|---|
[SerializeField] | Serialize a non-public field and show it in the inspector. Combine with [WasmSerialized] when the underlying type is a custom class. |
[Serializable] | Mark a custom class as Unity-serializable so its fields appear in the inspector. For WASM-serialized classes, pair with [WasmSerialized]. |
[DefaultExecutionOrder(int)] | Order among WasmBehaviours in the same VM. Does not affect order relative to Unity or CVR systems. See Events → Execution order. |
Unity editor attributes (inspector UX)
Section titled “Unity editor attributes (inspector UX)”These are stripped from the compiled WASM module by default to keep it small. They are preserved during Unity’s editor compile, so the inspector UX still works in the scene editor. To include them in the runtime module — useful if you reflect over fields at runtime — add UNITY_EDITOR_ATTRIBUTES to CCKWasmProjectDescriptor.projectDefines and enable enableReflection.
| Attribute | Purpose |
|---|---|
[Header("...")] | Inspector section header. |
[Tooltip("...")] | Inspector tooltip on hover. |
[Range(min, max)] | Slider for numeric fields. |
[Space] | Inspector vertical space. |
[HideInInspector] | Don’t show a public field in the inspector. |
[ColorUsage(...)] | Color picker configuration. |
[TextArea(...)] | Multi-line string input. |
[FormerlySerializedAs("...")] | Inspector-safe field rename. |
[ContextMenu("...")] | Adds an inspector right-click action. |
[ContextMenu] actions only fire in the editor, not at runtime in CVR.
Attributes you should not rely on
Section titled “Attributes you should not rely on”[RuntimeInitializeOnLoadMethod]— the Unity version; not invoked by the WASM pipeline.[DllImport]— native interop is impossible inside WASM.[Preserve](Unity.Scripting) — the NativeAOT compiler’s trimming is controlled byIlcDisableReflectionand project settings, not Unity’s preserve attribute.
Related
Section titled “Related”- Authoring — where these attributes fit in the workflow.
- Serialization — when to use which attribute.
- Unity Events Rewiring —
[ExternallyVisible]is required for UnityEvent-targeted methods.