【VRChat】Leveraging Attributes: Using UdonSynced, Header, and Range

Created: 2025-12-19

A list and usage guide for attributes available in UdonSharp. Synchronization with [UdonSynced], Inspector organization with [Header][Tooltip][Range], and improving development efficiency.

Overview

When writing UdonSharp code, you'll see notations enclosed in square brackets [] before class or variable declarations, like [UdonSynced]. These are called attributes, and rather than changing the logic of the code itself, they serve to add additional information or metadata to code elements (classes, methods, variables, etc.).

By mastering attributes, you can enable UdonSharp's synchronization features and dramatically organize the Unity Editor's Inspector window, improving development efficiency and maintainability.

This article explains the functionality and usage of particularly useful attributes in UdonSharp development.

UdonSharp-Specific Attributes

First, let's cover attributes directly related to UdonSharp functionality.

[UdonSynced]

  • Function: Makes a variable subject to network synchronization.
  • Target: Fields (variables).
  • Description: This fundamental attribute for network synchronization has appeared many times before. Variables with this attribute will have changes made by the owner reflected to all players in the instance.
[UdonSynced]
private int syncedScore = 0;

[RecursiveSync]

  • Function: Attempts to synchronize [UdonSynced] variables even when they're in UdonSharpBehaviours on child objects.
  • Target: Classes.
  • Description: Normally, [UdonSynced] variables are only synchronized within UdonSharpBehaviours attached to the same GameObject. Adding this attribute to a class includes synced variables in UdonSharpBehaviours on child GameObjects in the synchronization. This is convenient for objects with complex hierarchical structures, but performance impact should be considered.
[UdonBehaviourSyncMode(BehaviourSyncMode.Continuous)]
[RecursiveSync]
public class ParentObject : UdonSharpBehaviour
{
    // ...
}

Attributes for Improving Inspector Display

The following attributes control how public variables are displayed in the Unity Editor's Inspector window. This allows you to create gimmicks that are easy for others to understand and less prone to configuration mistakes.

[Header("Heading")]

  • Function: Displays a bold heading before a group of related variables in the Inspector.
  • Target: Fields (variables).
  • Description: Very useful for grouping multiple settings by function.

[Tooltip("Description")]

  • Function: Displays a description (tooltip) when hovering the mouse cursor over the variable name in the Inspector.
  • Target: Fields (variables).
  • Description: Useful for explaining what the setting is for and what values should be set.

[Space]

  • Function: Inserts blank lines in the Inspector, creating space between settings.
  • Target: Fields (variables).

[Range(min, max)]

  • Function: Makes int or float type variables adjustable with a slider.
  • Target: int or float type fields.
  • Description: Since you can restrict the range of values, this prevents invalid values (e.g., negative speed) from being set.

[HideInInspector]

  • Function: Hides public variables from displaying in the Inspector.
  • Target: Fields (variables).
  • Description: Use when you want other scripts to access the variable but don't need (or want) manual configuration in the Inspector.

Combined Attribute Usage Example

By combining these attributes, you can build a very understandable Inspector like this:

using UdonSharp;
using UnityEngine;

public class AttributeExample : UdonSharpBehaviour
{
    [Header("Movement Settings")]
    [Tooltip("Sets the player's base movement speed.")]
    [Range(1.0f, 10.0f)]
    public float moveSpeed = 3.0f;

    [Tooltip("Sets the player's movement speed when dashing.")]
    [Range(1.0f, 20.0f)]
    public float dashSpeed = 6.0f;

    [Space]

    [Header("Object References")]
    [Tooltip("Assign the Transform where the player respawns.")]
    public Transform spawnPoint;

    // Public but internal variable we don't want shown in Inspector
    [HideInInspector]
    public bool isInitialized = false;
}

The Inspector for an object with this script attached becomes very organized and intuitive to configure, with headings, sliders, and tooltips.

Summary

  • Attributes are powerful tools for adding metadata to code and changing UdonSharp and Unity Editor behavior.
  • [UdonSynced] is the fundamental UdonSharp attribute for network synchronizing variables.
  • By mastering attributes like [Header], [Tooltip], and [Range], you can make the Unity Editor's Inspector dramatically more understandable, making collaboration and future maintenance easier.
  • Properly utilizing attributes is an important technique for creating high-quality, reusable gimmicks.

These attributes don't change the script's logic itself but greatly improve the development experience. This is especially important when creating worlds with multiple people or when distributing gimmicks—having a well-organized Inspector is crucial.