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.

First Working Script

Create one local interaction before adding ownership, synced variables, or network events.

  1. Create an U# script in the Unity Project window.
  2. Add the behaviour and a Collider to an object, then assign its target.
  3. Enter Play Mode and interact with it through ClientSim.
World scripting only

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:

  1. Create or select a folder for the feature, such as Assets/World/Scripts/FirstInteraction.
  2. Right-click inside the folder.
  3. Choose Create > U# script.
  4. Name the file ToggleTargetOnInteract and 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.

Unity Project window example with separate UdonSharp script, program asset, prefab, and scene folders.
Keep scripts and their generated program assets together, and separate reusable prefabs from scene-only objects.

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, not MonoBehaviour.
  • The target field 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.
  • SetActive changes 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:

  1. Toggle Button — the object the player will interact with.
  2. Toggle Target — the object that will be shown or hidden.

On Toggle Button:

  1. Add a visible mesh if the object does not already have one.
  2. Add a Box Collider or another suitable Collider.
  3. Add the ToggleTargetOnInteract UdonSharp behaviour.
  4. Drag Toggle Target from the Hierarchy into the behaviour's Target field.

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.

  1. Move within interaction range of Toggle Button.
  2. Aim at its Collider.
  3. Use the interaction control.
  4. Confirm Toggle Target changes between active and inactive.
  5. 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 networking differs from VRChat

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:

  1. Console — resolve C# and UdonSharp compile errors.
  2. Component — confirm the UdonSharp behaviour is attached to Toggle Button.
  3. Target field — confirm Toggle Target is assigned.
  4. Collider — confirm the button has an enabled Collider at the expected size.
  5. Event signature — confirm the method is exactly public override void Interact().
  6. ClientSim — test from the Game view while the simulated player is within range.
  7. 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

Related Guides