Add Your First Interactive Button

Once you can open a VRChat world project and test a basic scene, the next useful step is making one object react when a player interacts with it.

This guide builds a simple local button with UdonSharp. Pressing the button toggles a separate target object on or off. That is deliberately small: it teaches the Interact() event, public inspector references, colliders, and testing without adding networking yet.

Build One Local Button

Start with a button that only changes what the local player sees. Shared synced state comes later, after the simple interaction works.

  1. Create a visible button object with a Collider.
  2. Create a separate target object the button will show or hide.
  3. Add a small UdonSharp script with Interact().
  4. Assign the target object in the Inspector and test with Build & Test.
VRChat note

This first button is local-only. It is perfect for learning the interaction path. If every player needs to see the same state, move to synced variables, ownership, and the existing synced-toggle examples after this works.

What You Are Making

You will make three things:

  • a button object players can interact with
  • a target object that appears or disappears
  • one UdonSharp script that toggles the target

Use this for a first test, not as the final version of every world system. A local button is good for personal visual feedback, private hints, local effects, tutorial panels, or learning how Udon hooks into scene objects.

Before You Start

Make sure:

  • the project is a VRChat Worlds project
  • Unity opens cleanly through Creator Companion
  • the VRChat SDK menu appears
  • the Console has no red compile errors
  • you have a simple scene that already works in Build & Test

If the project is broken before you add the button, pause here and use Fix Your First Broken VRChat Project.

1. Create The Button Object

In your scene:

  1. Create a small cube, cylinder, or other obvious button shape.
  2. Name it LocalToggleButton.
  3. Place it somewhere easy to reach.
  4. Add or confirm a Collider component.
  5. Make sure the button stays visible after the interaction.

Do not use the button itself as the target object for this first test. If the button hides itself, you may not be able to click it again.

2. Create The Target Object

Create a separate target object:

  1. Add a cube, sign, light prop, or simple marker.
  2. Name it ToggleTarget.
  3. Put it near the button so the change is obvious.
  4. Leave it active for the first test.

The target can be any GameObject you want to show or hide. Keep it simple until the script is working.

3. Create The UdonSharp Script

In the Project window, create a script named FirstInteractiveButton.cs.

Use this script:

using UdonSharp;
using UnityEngine;
using VRC.SDKBase;
using VRC.Udon;

public class FirstInteractiveButton : UdonSharpBehaviour
{
    [Header("Object this button shows or hides")]
    public GameObject targetObject;

    private bool isVisible = true;

    private void Start()
    {
        if (targetObject != null)
        {
            isVisible = targetObject.activeSelf;
        }
    }

    public override void Interact()
    {
        if (targetObject == null)
        {
            return;
        }

        isVisible = !isVisible;
        targetObject.SetActive(isVisible);
    }
}

This is intentionally small. The script checks whether a target is assigned, flips a boolean, and applies that state to the target object.

4. Attach And Assign It

On LocalToggleButton:

  1. Add the UdonSharp behaviour or Udon Behaviour that uses your FirstInteractiveButton program.
  2. Assign ToggleTarget to the targetObject field.
  3. Keep the Collider on the button object.
  4. Save the scene.

For a 3D object interaction, the interactable object needs a Collider and an Udon behaviour. If either is missing, Interact() will not fire when expected.

5. Test The Interaction

Use a small test loop:

  1. Clear the Console.
  2. Save the scene.
  3. Enter Play Mode or use VRChat Build & Test depending on what you are checking.
  4. Interact with the button.
  5. Confirm the target object turns off.
  6. Interact again and confirm it turns back on.

If the object toggles twice, your first button works.

6. Understand What Is Local

This script does not synchronize state.

That means:

  • it teaches the safest first interaction pattern
  • it avoids ownership and late-joiner problems
  • it is not the right final pattern for shared doors, shared lights, game state, or everyone-sees-it switches

When the button needs to affect everyone in the instance, use a synced example such as Global Toggle Switch (Synced) and read Udon Networking Decision Guide.

Common Beginner Problems

Help! Nothing happens when I click the button.

Check that the button object has a Collider, has the UdonSharp/Udon behaviour attached, and has the target assigned in the Inspector. Also check the Unity Console for compile errors.

Help! The button disappeared and I cannot turn it back on.

You probably assigned the button object as its own target. Use a separate target object so the button remains clickable.

Help! Other players do not see the toggle.

That is expected for this first local version. Move to synced variables, ownership, and the synced toggle examples when shared state matters.

Help! The script will not compile.

Make sure the file name and class name match, the project has UdonSharp available through the Worlds SDK, and there are no other red Console errors blocking compilation.

Should I use a Unity UI Button instead?

Use this guide for a physical 3D world object. For 2D UI, use the VRChat UI-events path and make sure the UI setup matches VRChat's allowed event targets.

What To Build Next

After this works, choose one next step:

Final Check

Your first interactive button is ready when:

  • the button has a Collider
  • the UdonSharp behaviour is attached
  • targetObject is assigned
  • the Console has no red compile errors
  • the target toggles off and on during testing
  • you understand whether the behavior is local or synced

That is enough for a first Udon interaction. Keep the first win small, then build the next system deliberately.

Helpful Follow-Up Pages

Official References

Related Navigation