Skip to main content

Scripting

Calling your script from a widget​

Set the widget's Target and Event Name. To receive the widget's value, also set Value Variable. UIHUD writes the value into that variable, then sends the event.

public class VolumePanel : UdonSharpBehaviour
{
[HideInInspector] public float volume; // Value Variable = volume
public AudioSource music;

public void OnVolumeChanged() // Event Name = OnVolumeChanged
{
music.volume = volume;
}
}

The method must be public, and the name must match exactly.

Values your scripts set are kept while the widget's page is hidden. A slider with an Audio Volume source starts at that source's volume, and its SetValue also sets the volume.

Manager​

MemberDoes
OpenMenu(), CloseMenu(), ToggleMenu()Same as the main button
ShowHud(), HideHud(), ToggleHud(), SetHudVisible(bool)HUD visibility
isMenuOpen, platformCurrent state. platform is Desktop, VR or Mobile.
IsTyping()The player is typing in a UIHUD text input
SetWristLeft(), SetWristRight(), SwapWristHand()The hand that wears the wrist button

For a Show HUD toggle, set Value Variable to hudVisibleValue and Event to _ApplyHudToggle. A toggle wired to ToggleHud gets out of step after your code calls HideHud.

For callbacks, set the manager's callbackTarget and onMenuOpenedEvent, onMenuClosedEvent or onPlatformChangedEvent.

Open(), Close(), Toggle(), ShowPage(i), NextPage(), PrevPage(), and SetSideLeft(), SetSideRight(), SetSideTop(), SetSideBottom(), SetSideCenter().

Each menu also has callbackTarget with onOpenEvent, onCloseEvent and onPageChangedEvent.

Hotbar​

Select(i), SelectNext(), SelectPrevious(), Deselect(), SelectedSlot(), selectedIndex, Show(), Hide(), ToggleVisible(). Call RefreshSlots() after adding a slot at runtime:

manager.AddWidget("Toggle", hotbar.content, "Light");
hotbar.RefreshSlots();

Runtime widgets​

Udon can't add components, so UIHUD copies hidden templates. On the manager, click Add widgets at runtime > Make runtime templates. Click it again after changing the style.

GameObject b = manager.AddWidget("Button", page, "Teleport");
manager.SetEvent(b, this, nameof(OnTeleport), "");
manager.SetLabel(b, "Teleport (2)");
manager.RemoveWidget(b);

Kinds: Button, Toggle, Slider, Label, Header, Bar, Radial, Notification, Image, Space, Divider, Selector, Input, PlayerList, Info, Row, Grid, Scroll. The data widgets Value, Table and Graph also work after you rebuild the templates. An unknown kind returns null.

Runtime widgets are local. Other players don't see them.

Data widgets​

Pie and Bar List​

Both take named numbers in any of these forms:

  • a DataDictionary, such as {"Red": 4}
  • a DataList of dictionaries, using labelKey and valueKey
  • a DataList of [name, value] lists
  • the same data as JSON (SetJson)

Use SetEntry(name, value) to change one entry, and Clear() to remove them all. A pie has 8 slices, and further entries are merged into Other. A bar list shows 6 rows, sorted from largest to smallest.

Table​

SetList, SetDictionary, SetData, SetJson, Render().

FieldDefaultMeaning
columnsname, scoreKeys to read
titlesPlayer, ScoreColumn headings
sortByscoreSort column
descendingtrueSort order
showRanktrueShow a rank column
maxRows10Rows shown
maxCellChars16Longer text is cut and ends in ...
highlight{me}Highlights your own row
emptyTextNo dataShown when there are no rows

Graph​

AddSample(v), SetSamples(float[]), Clear(), SetStyle(0) for a line or SetStyle(1) for bars. It holds 30 points.

A widget on a hidden page or a closed menu doesn't run, so its watched variable is sampled only while it is visible. To keep history, call AddSample from a script that is always active.

Single values​

WidgetUse
StatSetValue(v) shows the number and its change. higherIsBetter swaps the colours.
GaugeSetValue(v) between min and max
ValueShows a variable with a format, such as Coins: {0}
InfoA template with {time} {time12} {date} {players} {fps} {name} {uptime} {height}
BarSetValue(current, max), SetCurrent(v), Add(delta)
NotificationShow("text") queues a message

Networking​

UIHUD syncs nothing. To share state, sync it in your own script and update the widgets on each player. The ExampleWorldCounter and ExamplePoll samples show how.

Sample scripts​

Import Examples from the Package Manager.

ScriptShows
ExampleHealthButtons calling your methods and driving a HUD bar
ExampleSettingsPassing widget values to a script
ExampleRuntimeListAdding and removing widgets at runtime
ExampleShopA shop panel with a live coin value
ExampleMenuEventsManager callbacks
ExampleWorldCounterA synced counter
ExamplePollA synced poll using [NetworkCallable]