Attributes List
A collection of attributes to create custom UIs for your own behaviours

Class Attributes

The following attributes are only available to use with your behaviour classes.

CustomName

[CustomName(string name)]
Sets a custom name shown in the header bar, otherwise the header bar is hidden.
1
[CustomName("My Fancy Controller")]
2
public class MyUdonSharpBehaviour : UdonSharpBehaviour {}
Copied!

HelpMessage

[HelpMessage(string message)]
Displays a box with some text below the controller's header bar and above the rest of the UI. Usually used to describe the purpose of the behaviour if it is not obvious, or to warn user about anything in particular.
1
[HelpMessage("This behaviour should be enabled at all times")]
2
public class MyUdonSharpBehaviour : UdonSharpBehaviour {}
Copied!

OnBeforeEditor

[OnBeforeEditor(string methodName)]
Calls the specified method every editor update loop before all the editor code was executed. The SerializedObject is passed to your method as a parameter which you can use to perform any necessary modifications.
1
[OnBeforeEditor("BeforeEditor")]
2
public class MyUdonSharpBehaviour : UdonSharpBehaviour {
3
public void BeforeEditor(SerializedObject obj) {
4
// do stuff
5
}
6
}
Copied!

OnAfterEditor

[OnAfterEditor(string methodName)]
Calls the specified method every editor update loop after all the editor code was executed. This will contain all the latest values before they are saved into the object. The SerializedObject is passed to your method as a parameter which you can use to perform any necessary modifications.
1
[OnAfterEditor("AfterEditor")]
2
public class MyUdonSharpBehaviour : UdonSharpBehaviour {
3
public void AfterEditor(SerializedObject obj) {
4
// do stuff
5
}
6
}
Copied!

OnValuesChanged

[OnValuesChanged(string methodName)]
Calls the specified method whenever any value has been changed by the user in the inspector. The SerializedObject is passed to your method as a parameter which you can use to perform any necessary modifications.
If you need to react to a specific value change - use a field-level OnValueChanged attribute
1
[OnValuesChanged("ValuesChangeHandler")]
2
public class MyUdonSharpBehaviour : UdonSharpBehaviour {
3
public void ValuesChangeHandler(SerializedObject obj) {
4
// do stuff
5
}
6
}
Copied!

Field Attributes

These attributes are meant to go on public fields of your Controller. They serve as UI building blocks and provide an ability to react to value changes, for example if you would like to do something specific in the scene when user checks a checkbox.

Attribute Order

Some attributes affect whether the field is displayed or not, for those - order of the attributes is important. As soon as the editor encounters an attribute that hides a field - the field will be hidden no matter what the consecutive attributes return. The order is from the topmost attribute to the one right before the public keyword.
1
// this will hide the whole field based on the value of `someBool`
2
[SectionHeader("Other Test")]
3
[HideIf("@someBool")]
4
public float var;
5
6
public bool someBool;
Copied!
Many of these attributes can be combined to form more elaborate UI systems, so something like this is completely normal
1
[OnValueChanged("HandleChange"]
2
[HelpBox("Value cannot be negative", "CheckValueValidity")]
3
[HideIf("@!transition")]
4
[HideLabel]
5
public float duration;
Copied!

Common Parameters

Some attributes share parameter names. One of such parameters is methodName. In most cases you will be able to pass either a method, or a variable name to it (where it makes sense, there are exceptions, and they are mentioned separately).
1
// Will execute `ShouldShowBox` to determine whether the box should be visible
2
[HelpBox("", "ShouldShowBox")];
3
public bool active;
4
5
// Must return `bool`
6
public bool ShouldShowBox() {
7
return active;
8
}
Copied!
To use a variable instead of a method - prefix the variable name with @, you can also invert the variable value by adding ! after that.
1
// Will show if active is `true`
2
[HelpBox("", "@active")];
3
public bool active;
4
5
// Will show if active is `false`
6
[HelpBox("", "@!active")];
7
public bool active;
Copied!
This can be any public variable of a class, doesn't have to be specifically the same variable. You can use something like [HideInInspector] for storing the state of the box without displaying it in the editor.

SectionHeader

[SectionHeader(string title)]
Displays a visual separator box with some text
1
[SectionHeader("General")]
2
public Transform sourceTransform;
Copied!

HelpBox

[HelpBox(string message, [string methodName])]
Displays a box with a help message. You can conditionally hide and show the box based on a method or variable. See Common Parameters for more info.
1
// Always visible
2
[HelpBox("This option disables rotation transfer")]
3
public bool ignoreRotation;
4
5
// Only visible if provided variable is set to `true`
6
[HelpBox("This option disables rotation transfer", "@ignoreRotation")]
7
public bool ignoreRotation;
8
9
// Only visible if provided variable is set to `false`
10
[HelpBox("This option disables rotation transfer", "@!ignoreRotation")]
11
public bool ignoreRotation;
12
13
// Only visible if the provided method returns `true`
14
[HelpBox("This option disables rotation transfer", "ShowIgnoreHelp")]
15
public bool ignoreRotation;
16
17
public bool ShowIgnoreHelp() {
18
return ignoreRotation;
19
}
Copied!

HideIf

[HideIf(string methodName)]
Hides the field based on the provided method or variable. See Common Parameters for more info.
1
public bool enableEffects = true;
2
3
// Hides the field if `enableEffects` is unchecked
4
[HideIf("@!enableEffects")]
5
public float effectsDuration;
6
7
public bool skipTransition;
8
9
// Hides the field if `skipTransition` is checked
10
[HideIf("This option disables rotation transfer", "@skipTransition")]
11
public float transitionDuration;
12
13
// Hides the fields if the provided method returns true
14
public bool enableEffects;
15
public float effectsDuration;
16
17
[HideIf("HideExtras")]
18
public bool extraOption1;
19
20
[HideIf("HideExtras")]
21
public bool extraOption2;
22
23
public bool HideExtras() {
24
return enableEffects && effectsDuration > 0;
25
}
Copied!

HideLabel

[HideLabel]
Simply hides the field label and draws the value field only. Helpful in combinations with things like Horizontal attribute
1
// Will show the field only
2
[HideLabel]
3
public GameObject active;
Copied!

Tab Group

[TabGroup(string name, [string variableName])]
Creates a tab system which only displays properties assigned to a particular tab.
All tabs will be displayed where the [TabGroup] will be first encountered. So if your first [TabGroup] is added to the 5th property of the object - the whole tab system will show up right above the 5th property. That is the current limitation of the system that might be adjusted at some point
1
[TabGroup("Basics")]
2
public bool basicSettingA;
3
4
[TabGroup("Basics")]
5
public bool basicSettingB;
6
7
[TabGroup("Advanced")]
8
public float advancedSettingA;
9
10
[TabGroup("Advanced")]
11
public float advancedSettingB;
12
13
// you can have any amount of properties inside a tab
14
[TabGroup("Advanced")]
15
public Vector3 advancedSettingC;
Copied!
Tabs support any kind of attributes within them, e.g. you can use a [FoldoutGroup] inside a tab
1
[TabGroup("TabA")]
2
[FoldoutGroup("Stuff in Tab A")]
3
public bool vA;
4
5
[TabGroup("TabA")]
6
[FoldoutGroup("Stuff in Tab A")]
7
public bool vB;
8
9
10
[TabGroup("TabB")]
11
public float vC;
12
[TabGroup("TabB")]
13
public float vD;
Copied!
You can also pass a variableName to the [TabGroup] to save the currently selected tab index to that variable. You only need to provide that option to the first instance of TabGroup in the file.
This is often used to create different "modes" for a behaviour which you can then use in the code.
1
[TabGroup("Collide With Objects", "collisionType")]
2
public LayerMask collideWith;
3
4
[TabGroup("Collide With Players")]
5
public bool collideWithLocalPlayers;
6
[TabGroup("Collide With Players")]
7
public bool collideWithRemotePlaers;
8
9
// We save the selected type into this variable to use in Udon code later
10
[HideInInspector]
11
public int collisionType;
Copied!

Foldout Group

[FoldoutGroup(string name)]
A general purpose foldout allowing you to nest properties inside of it
1
[FoldoutGroup("Foldout")]
2
public float floatInFoldout;
3
4
[FoldoutGroup("Foldout")]
5
public bool boolInFoldout;
6
7
// You can nest other layout elements inside the FoldoutGroup
8
[FoldoutGroup("Foldout")]
9
[Horizontal("Horizontal In Foldout", true)]
10
public GameObject objInFoldout;
11
12
[FoldoutGroup("Foldout")]
13
[Horizontal("Horizontal In Foldout", true)]
14
public float floatInHorizontalInFoldout;
15
16
[FoldoutGroup("Foldout")]
17
[ListView("ListViewInFodlout")]
18
public UdonSharpBehaviour[] foldoutTargets;
19
20
[FoldoutGroup("Foldout")]
21
[ListView("ListViewInFodlout")]
22
[Popup("behaviour", "@foldoutTargets")]
23
public string[] foldoutEvents;
Copied!

OnValueChanged

[OnValueChanged(string methodName)]
Calls provided method when the value of the variable changes, so you can react to it in the UI. Has some special behaviour when used together with ListView.
Due to limitations of Udon - the use of #if !UDONSHARP_COMPILER && UNITY_EDITOR is required for the handler methods
For regular fields the method signature should look like public void MethodName(SerializedProperty value)
1
// Will call the provided method with the fresh value every time it changes
2
[OnValueChanged("ToggleLights")]
3
4
// Incoming value will be the new value, while the current variable will not be updated yet.
5
// This allows you to compare old and new values.
6
#if !COMPILER_UDONSHARP && UNITY_EDITOR
7
public void ToggleLights(SerializedProperty value) {
8
// cast to the expected type first
9
var val = value?.boolValue;
10
if (value) {
11
// do something here
12
} else {
13
// do something here
14
}
15
}
16
#endif
Copied!
For array type fields the method signature is public void MethodName(SerializedProperty value, int index)
1
[OnValueChanged("HandleArrayChange")]
2
public string[] namesList;
3
4
#if !COMPILER_UDONSHARP && UNITY_EDITOR
5
public void HandleArrayChange(SerializedProperty value, int index) {
6
// if value is `null` - the value at `index` was removed
7
if (value == null) {
8
// handle removal
9
return;
10
}
11
// if `index` is out of range of the current array - a new value was added
12
if (index == namesList.length) {
13
// handle addition of new value
14
return;
15
}
16
// handle change of an existing value
17
}
18
#endif
Copied!
When used with ListView the method signature should be different: public void MethodName(object lValue, object rValue, int index), where lValue and rValue represent the left and right variable of the list view at the changed index.
You only need to attach [OnValueChanged] to the first instance of a particular ListView.
1
[OnValueChanged("HandleChange")
2
[ListView("Events List")]
3
public UdonBehaviour[] udonTargets;
4
5
[ListView("Events List")]
6
public string[] udonEvents;
7
8
// Handle a change of row values
9
#if !COMPILER_UDONSHARP && UNITY_EDITOR
10
public void HandleChange(SerializedProperty lValue, SerializedProperty rValue, int index) {
11
// when the value is removed - both will be null
12
if (lValue == null && rValue == null) {
13
// handle the removal of a row at `index` here
14
return;
15
}
16
// when the value is added - `index` will be out of range of the current list
17
if (index == udonTargets.Length) {
18
// handle addition of new row
19
return;
20
}
21
var lCasted = (UdonBehaviour) lValue?.objectReferenceValue;
22
var rCasted = rValue?.stringValue;
23
// handle change of an existing values
24
}
25
#endif
Copied!
If you wish to get a full value instead of just the changed elements in both Array types and the ListView powered blocks, you will need to use a different signature.
    For regular arrays: public void MethodName(SerializedProperty[] value)
    For ListView blocks: public void MethodName(SerializedProperty[] lValue, SerializedProperty[] rValue)
If you also want to update some other value on the same object inside the change handler function - you need to accept an incoming SerializedObject as well
    For regular arrays: public void MethodName(SerializedObject obj, SerializedProperty[] value)
    For ListView blocks: public void MethodName(SeriazliedObject obj, SerializedProperty[] lValue, SerializedProperty[] rValue)
You can then use it to update properties like obj.FindProperty("someProp").floatValue = 0.01f
1
[OnValueChanged("HandleArrayChange")]
2
public string[] namesList;
3
4
// Log current array value as `Values: array[0], array[1]...`
5
#if !COMPILER_UDONSHARP && UNITY_EDITOR
6
public void HandleArrayChange(SerializedProperty[] value) {
7
var casted = value.ToList();
8
// don't forget to grab the value of needed type or cast it from i.objectReferenceType as <yourTargetType>
9
Debug.LogFormat("Values: {0}", string.Join(", ", casted.Select(i => i.floatValue).ToArray()));
10
}
11
#endif
12
13
// Works for `ListView too
14
[OnValueChanged("Hand`leChange")
15
[ListView("Events List")]
16
public UdonBehaviour[] udonTargets;
17
18
[ListView("Events List")]
19
public string[] udonEvents;
20
21
// Log current `ListView` value as `Event: udonEvents[i], Target udonTargets[i].name`
22
#if !COMPILER_UDONSHARP && UNITY_EDITOR
23
public void HandleChange(SerializedProperty[] lValue, SerializedProperty[] rValue) {
24
var cLeft = leftVal.ToList();
25
var cRight = rightVal.ToList();
26
var eventNames = new List<string>();
27
for (int i = 0; i < cLeft.Count; i++) {
28
var behName = cLeft[i].objectReferenceValue != null
29
? (cRight[i].objectReferenceValue as UdonBehaviour).name
30
: "null";
31
eventNames.Add(quot;Event: {cRight[i].stringValue}, Target: {behName}");
32
}
33
Debug.Log(string.Join("\n", eventNames));
34
}
35
#endif
36
37
[OnValueChanged("HandleSliderChange")] [RangeSlider(0, 2)]
38
public float someFloat = 0.2f;
39
40
public bool someBoolProp;
41
42
// Modify another property in response to a value change
43
#if !COMPILER_UDONSHARP && UNITY_EDITOR
44
public void HandleSliderChange(SerializedObject obj, SerializedProperty value) {
45
obj.FindProperty("someBoolProp").boolValue = value.floatValue > 1;
46
}
47
#endif
Copied!
Check CustomUISample.cs for live examples!

Horizontal

[Horizontal(string groupName, [bool showHeader])]
Combines multiple fields into a horizontal group based on the provided name. You can define variables in any order, they can even have other variables between them. The fetching is done purely by the group name.
You can also pass a showHeader bool to display the group name in the UI.
1
// When using object types its pretty common to use a `[HideLabel]` attribute to make the UI cleaner
2
[Horizontal("Group")]
3
public GameObject varA;
4
5
[Horizontal("Group")]
6
public string varB;
7
8
// You can have many groups
9
[Horizontal("OtherGroup")]
10
public int varC;
11
12
[Horizontal("OtherGroup")]
13
public int varD;
14
15
// Display the group name in the UI
16
[Horizontal("I'm a group!", true)]
17
public int varE;
18
19
[Horizontal("I'm a group!")]
20
public int varF;
21
22
// You can have more than 2 elements in a group!
23
[Horizontal("I'm a group!")]
24
public int varG;
25
Copied!

ListView

[ListView(string name, [string addMethodName], [string addButtonText])]
Combines arrays into a connected list of elements.
This is a cornerstone attribute of UdonToolkit. Due to dictionaries not being exposed in Udon we have to split things into separate arrays which makes navigating logically connected pieces of data very annoying, as well as forcing you to manually keep track of having enough elements in both arrays.
ListView covers that use case and provides some extras when combined with the Popup attribute.
1
[ListView("Udon Events List")]
2
public UdonBehaviour[] udonTargets;
3
4
[ListView("Udon Events List")]
5
public string[] udonEvents;
Copied!
You can provide a custom add method to have full control on how the arrays are populated. It is also a good way to create something in the scene, like an instance of a prefab or a basic GameObject and set it as the list value at the same time.
You only need to configure the extra parameters in the first instance of ListView for a particular group.
1
// You can also customize the add button text via an extra argument
2
[ListView("Udon Events List", "AddEvent", "Add new Event")]
3
public UdonBehaviour[] udonTargets;
4
5
// No need to define extra configuration here, the first instance of `ListView` for that group name is going to be used
6
[ListView("Udon Events List")]
7
public string[] udonEvents;
8
9
// The addition is fully relegated to your custom method, you can do whatevery you find suitable in here
10
public void AddEvent() {
11
var newTargets = udonTargets.ToList();
12
newTargets.Add(null);
13
udonTargets = newTargets.ToArray();
14
15
var newEvents = events.ToList();
16
newEvents.Add(quot;NewEvent_{events.Length}");
17
events = newEvents.ToArray();
18
}
Copied!
Combining it with a [Popup] attribute is the way this is used the most across Udon Toolkit's behaviours. Creating list of Udon events and Animator triggers becomes a matter of a single line of code that handles everything behind the scenes.
1
[ListView("Udon Events List")]
2
public UdonBehaviour[] udonTargets;
3
4
// You can combine many attributes together, here we use `Popup` to automatically populate the events list for us
5
[ListView("Udon Events List")]
6
[Popup("behaviour", "@udonTargets", true)]
7
public string[] udonEvents;
Copied!
You can read more about [Popup] and how it can be populated right here

RangeSlider

[RangeSlider(float min, float max)]
Provides a slider to control the value in a predefined range, supports both floats and ints.
1
[RangeSlider(1, 10)]
2
public float floatValue;
3
4
// If the value is int - slider will auto snap to only int values
5
[RangeSlider(3, 20)
6
public int intValue;
Copied!
[Popup(string methodName)]
Shows a popup with options to choose from and support for multiple sources of data. Only supported on string and int variable types, as well as their array variants at this time.
If used on an int or int[] it will save the index of the selected option in the list - into your target variable. So on the image above - selecting fizz will save 2 into popupVar
You can provide a method, or a variable, to populate the popup options list. See Common Parameters for more info.
1
// Use a variable to populate the popup options
2
[SectionHeader("Popups")] [Popup("@popupOptions")]
3
public string popupVar;
4
5
[NonSerialized] public string[] popupOptions = {"foo", "bar", "fizz", "buzz"};
6
7
// You can also use a method to calculate options dynamically
8
[SectionHeader("Popups")] [Popup("GetOptions")]
9
public string popupVar;
10
11
public string[] GetOptions() {
12
return new [] { "foo", "bar", "fizz", "buzz" };
13
}
14
15
// The method can accept a serialized property if you want to dynamically generate the options
16
#if !COMPILER_UDONSHARP && UNITY_EDITOR
17
public string[] GetOptions(SerializedProperty prop) {
18
return new [] { quot;options for {prop.name}" };
19
}
20
#endif
Copied!
By providing an explicit sourceType other than method you can use the built-in Toolkit's ability to fetch a list of Animator Triggers, Udon Behaviour Custom Events or Shader Properties of a particular type. If there are no triggers or events available - the UI will inform you about it.
There are plans to add more sources in the future, like Material properties and other native elements.
You can combine this with [ListView] attribute to achieve dictionary-style results for Udon Behaviours. When used inside ListView - the popup method will be called with the Serialized Property of the current element on the opposing array (see example below).
1
// a namespace to work with Lists
2
#if !COMPILER_UDONSHARP && UNITY_EDITOR
3
using System.Collections.Generic;
4
#endif
5
// We use `[Horizontal]` to visually connect the source and the popup
6
[Horizontal("AnimationTrigger")] [HideLabel]
7
public Animator animator;
8
9
// Using an Animator source type to auto fetch Triggers from the `animator` variable
10
[Horizontal("AnimationTrigger")] [Popup("animator, "@animator", true)]
11
public string somePopupVar;
12
13
[Horizontal("BehaviourTrigger")] [HideLabel]
14
public UdonBehaviour behaviour;
15
16
// Using an UdonBehaviour source type to auto fetch Custom Events from the `behaviour` variable
17
[Horizontal("BehaviourTrigger")] [Popup("behaviour", "@behaviour", true)]
18
public string behaviourPopupVar;
19
20
[Horizontal("ShaderProperty")] [HideLabel]
21
public Shader shader;
22
23
// Using a Shader source type to auto fetch `float` Shader Properties from the `shader` variable
24
[Horizontal("ShaderProperty")] [Popup("shader", "@shader", true)]
25
public string shaderPopupVar;
26
27
// You can also specify which type of shader proeprty to grab
28
[Popup("shader", "@shader","vector", false)]
29
public string shaderPopupVectorVar;
30
31
[ListView("Test List")]
32
public Transform[] transforms;
33
34
[ListView("Test List")]
35
[Popup("GetChildrenOptions")]
36
public string[] selectedChildren;
37
38
#if !COMPILER_UDONSHARP && UNITY_EDITOR
39
// prop in this case is the element of `transforms` array on the current index
40
public string[] GetChildrenOptions(SerializedProperty prop) {
41
var transObj = (Transform) prop.objectReferenceValue;
42
if (transObj == null) {
43
return new[] { "-- no transform set --"};
44
}
45
var childList = new List<string>();
46
for (int i = 0; i < transObj.childCount; i++) {
47
var child = transObj.GetChild(i);
48
childList.Add(child.name);
49
}
50
51
return childList.ToArray();
52
}
53
#endif
Copied!

Toggle

[Toggle([string label])]
Toggle-type button for boolean fields.
Combines well with things like [HideIf] attribute to toggle parts of the UI on and off to hide things that are unused in a particular toggle state.
1
// Use the variable name as the toggle label
2
[Toggle]
3
public bool addSFX;
4
5
// Combine with [HideIf] to hide a variable that is irrelevant if the toggle is `false`
6
[HideIf("@!addSFX")]
7
public float someThirdVar;
8
9
// Use a custom toggle label
10
[Toggle("Custom Label")]
11
public bool extraToggle;
Copied!

Disabled

[Disabled([string methodName])]
Disables the editing of the provided field completely, or based on the provided methodName. Useful when manually populating fields via editor scripts (like with OnValueChanged) or in runtime.
When used with ListView it should be put on the first field in the list view.
1
// Make a field read only
2
[Disabled]
3
public bool toggleThings;
4
5
// Make a field read only based on a method return value
6
[Disabled("GetDisabled")]
7
public float disabledFloat;
8
9
public bool GetDisabled() {
10
return gameObject.activeSelf;
11
}
12
13
public bool allowEditing;
14
15
// Make a list view read only
16
[ListView("Stuff")][Disabled("@!allowEditing")]
17
public Transform[] objects;
18
19
[ListView("Stuff")]
20
public string[] objectDescriptions;
Copied!

Method Attributes

These attributes are meant to be added to your public methods and are handled separately. The UI for these is rendered after the main inspector is done, so they will always be at the bottom.

Button

[Button(string text)]
Displays a button that calls the specified method in editor only. For example if you want to write some setup logic - you can use this attribute to provide a handy button for it.
1
[Button("Helper Button")]
2
public void CustomButton() {
3
Debug.Log("Pressed the Helper Button");
4
}
Copied!
Last modified 7mo ago