UdonSharp Guide: Create Your First Interaction
UdonSharp lets VRChat world creators write Udon scripts with C#. It is included in the VRChat Worlds SDK and compiles an UdonSharpBehaviour into Udon Assembly that can run in Unity and VRChat.
This guide creates an interactable object that toggles another GameObject. It covers the full path from the script asset to an in-editor ClientSim test.
Create one local interaction before adding ownership, synced variables, or network events.
- Create an U# script in the Unity Project window.
- Add the behaviour and a Collider to an object, then assign its target.
- Enter Play Mode and interact with it through ClientSim.
Udon and UdonSharp run in VRChat worlds. They are not avatar scripting systems. Create and manage the project as a Worlds project through VRChat Creator Companion.
Udon, Udon Graph, and UdonSharp
| Tool | Role |
|---|---|
| Udon | VRChat's world scripting environment and virtual machine |
| Udon Graph | Visual node-and-wire authoring for Udon programs |
| UdonSharp | C# authoring that compiles to Udon Assembly |
| ClientSim | Unity editor simulation for testing many common VRChat interactions |
Udon Graph and UdonSharp target the same Udon runtime. Use Udon Graph when a small visual program is easier to understand; use UdonSharp when code, reusable methods, and typed fields make the behavior clearer.
Create the Script Assets
In the Unity Project window:
- Create or select a folder for the feature, such as
Assets/World/Scripts/FirstInteraction. - Right-click inside the folder.
- Choose Create > U# script.
- Name the file
ToggleTargetOnInteractand select Save.
UdonSharp creates two connected assets in the same folder:
| Asset | Purpose |
|---|---|
ToggleTargetOnInteract.cs |
The C# source file you edit |
| UdonSharp Program Asset | The compiled Udon program linked to that source |
You normally edit the .cs file and leave the program asset linked to it.
Write the Interaction
Replace the generated class with this local toggle:
using UdonSharp;
using UnityEngine;
public class ToggleTargetOnInteract : UdonSharpBehaviour
{
public GameObject target;
public override void Interact()
{
if (target == null)
{
return;
}
target.SetActive(!target.activeSelf);
}
}
The important pieces are:
- The class inherits from
UdonSharpBehaviour, notMonoBehaviour. - The
targetfield is public so it can be assigned in the Unity Inspector. Interact()is a public override of the VRChat interaction event.- The null check prevents the behavior from trying to use an unassigned target.
SetActivechanges only the local client's copy of the object in this version.
Save the script and return to Unity. Wait for compilation to finish before adding it to the scene.
Build the Scene Objects
Create two GameObjects:
- Toggle Button — the object the player will interact with.
- Toggle Target — the object that will be shown or hidden.
On Toggle Button:
- Add a visible mesh if the object does not already have one.
- Add a Box Collider or another suitable Collider.
- Add the
ToggleTargetOnInteractUdonSharp behaviour. - Drag Toggle Target from the Hierarchy into the behaviour's
Targetfield.
VRChat only sends interaction events to GameObjects that have both a Collider and an Udon Behaviour. Size the Collider around the surface the player should point at.
Test with ClientSim
Open the world scene and press Play. ClientSim runs the Game view as a simulated local VRChat player.
- Move within interaction range of Toggle Button.
- Aim at its Collider.
- Use the interaction control.
- Confirm Toggle Target changes between active and inactive.
- Exit Play Mode and confirm the scene returns to its saved edit-time state.
ClientSim supports common features such as Interacts, pickups, UI, and stations, but it does not reproduce every part of the VRChat client. Always build and test the world in VRChat before publishing.
Understand the Local Result
The example does not synchronize its state. In a multiplayer instance, each player can toggle their own local copy independently.
| Required behavior | Next design step |
|---|---|
| Each player controls a private visual | Keep the interaction local |
| Everyone must see the same current state | Add ownership and synchronized state |
| Every player should run a one-time action | Consider a network event |
| A value must survive reconnecting or instance changes | Review VRChat persistence systems |
Adding [UdonSynced] to a field is only one part of networking. Ownership determines who can serialize the value, and manual synchronization requires an explicit serialization request. Design the ownership path before converting this first script into a shared toggle.
ClientSim simulates a local player, but its networking serializer and remote-player behavior are not identical to VRChat. Use a VRChat build when validating ownership, serialization, late joiners, and multiple clients.
C# Features That Need Different Treatment
UdonSharp supports much of C#'s basic syntax, but it is not conformant to a specific C# language version.
| Ordinary C# pattern | UdonSharp consideration |
|---|---|
MonoBehaviour script |
Inherit from UdonSharpBehaviour |
List<T> and other generic collections |
Use arrays or supported VRChat data containers |
| Scene-dependent field initializer | Perform scene-dependent initialization in Start() |
| Synced field | Add [UdonSynced] and implement the required networking flow |
| Any Unity class or method | Check the UdonSharp class exposure tree |
If a Unity tutorial uses an API that does not compile in UdonSharp, verify that the class and method are exposed to Udon before looking for a syntax workaround.
Debugging Order
When the interaction fails, inspect it in this order:
- Console — resolve C# and UdonSharp compile errors.
- Component — confirm the UdonSharp behaviour is attached to Toggle Button.
- Target field — confirm Toggle Target is assigned.
- Collider — confirm the button has an enabled Collider at the expected size.
- Event signature — confirm the method is exactly
public override void Interact(). - ClientSim — test from the Game view while the simulated player is within range.
- VRChat build — verify behavior that depends on the real client or networking.
Do not add synchronization while the local interaction is still failing. Networking adds ownership and serialization variables that make a basic setup error harder to isolate.
Video Companion
This beginner world-creation video introduces Udon interactions in the context of a VRChat scene. Use the written steps above for the current UdonSharp asset and Inspector workflow.
Troubleshooting
Create > U# script does not appear.
Confirm the project is a VRChat Worlds project managed through Creator Companion. Resolve SDK package and Console errors, then let Unity finish compiling before checking the Create menu again.
The script cannot be added to the GameObject.
Fix every Console compile error first. Also confirm the file name and public class name are both `ToggleTargetOnInteract` and that the class inherits from `UdonSharpBehaviour`.
No interaction prompt appears in ClientSim.
Confirm the same GameObject has an enabled Collider and the UdonSharp behaviour. Check the Collider size and move the simulated player close enough to point at it.
The prompt appears, but the target does not change.
Inspect the UdonSharp component and assign the `Target` field. Then confirm the method signature remains `public override void Interact()`.
The toggle works for me but not for other players.
The example is intentionally local. Shared state requires a networking design that covers ownership, synchronized variables or network events, serialization, and late joiners.
The script works in ClientSim but fails in VRChat.
Check the VRChat client log and SDK build warnings, then review any networking or API assumptions. ClientSim cannot reproduce every client feature and has documented networking differences.
Official References
- VRChat UdonSharp
- VRChat Udon Basics Examples
- VRChat Udon
- VRChat ClientSim
- UdonSharp Attributes
- UdonSharp Configuration