udonsharp-coding
A guide for coding with UdonSharp. Use this when you are asked to create or edit UdonSharp programs. Code that inherits from UdonSharpBehaviour falls under UdonSharp code.
What this skill does
UdonSharp generally follows C# syntax, but its features are limited.
# Supported C# Features
- Flow control: `if`, `else`, `while`, `for`, `do`, `foreach`, `switch`, `return`, `break`, `continue`, `ternary operator (condition ? true : false)`, `??`
- Implicit and explicit type conversions
- Arrays and array indexers
- All built-in arithmetic operators
- Conditional short circuiting `(true || CheckIfTrue())` will not execute `CheckIfTrue()`
- `typeof()`
- Extern methods with `out` or `ref` parameters, such as many variants of `Physics.Raycast()`
- User defined methods with parameters and return values, supports out/ref, extension methods, and `params`
- User defined properties
- Static user methods
- UdonSharpBehaviour inheritance, virtual methods, etc
- Unity/Udon event callbacks with arguments. For instance, registering an `OnPlayerJoined` event with a `VRCPlayerApi` argument is valid.
- String interpolation
- Field initializers
- Jagged arrays
- Referencing other custom UdonSharpBehaviour classes, accessing fields, and calling methods on them
- Recursive method calls are supported via the `[RecursiveMethod]` attribute
# Differences from Unity C#
- Udon currently only supports array `[]` collections and by extension UdonSharp only supports arrays at the moment.
- Field initializers are evaluated at compile time, if you have any init logic that depends on other objects in the scene you should use Start for this.
- Use the UdonSynced attribute on fields that you want to sync.
- Numeric casts are checked for overflow due to UdonVM limitations
- The internal type of variables returned by `.GetType()` will not always match what you may expect since U# abstracts some types in order to make them work in Udon. For instance, any jagged array type will return a type of `object[]` instead of something like `int[][]` for a 2D int jagged array.
## Instantiate
You cannot create a new GameObject using `new GameObject()` and similar APIs. In UdonSharp, you create new objects by cloning an existing `GameObject` in the scene using `Instantiate()`. Additionally, only `GameObject` can be instantiated via `Instantiate()`.
# Best Practices
## Use `Utilities.IsValid` for null checks
`bool IsValid(object obj)` returns true when `obj` is not null (or is otherwise valid). In UdonSharp, this is faster than doing null checks with `==`.
# Editor Build-Time Scene Generation
If you need to generate GameObjects or `UdonBehaviour` components during scene build processing, read `references/build_time_scene_generation.md`. For a Japanese human-readable explanation of the same guidance, read `references/build_time_scene_generation.ja.md`.
# Basic Template
```cs
using UdonSharp;
using UnityEngine;
using VRC.SDKBase;
using VRC.Udon;
public class UdonSharpScript : UdonSharpBehaviour
{
}
```
# Networking
If the problem you are addressing involves network synchronization, read the document `references/en/udon_network/README.md`. These documents describe the concepts and methods required to implement network logic in Udon.
# Class Design
If you need shared logic, encapsulation, or inheritance, be aware that UdonSharp has important limitations. See `references/en/udon_class.md`.
# Player Tracking
If you are implementing things like gaze-following objects or objects that follow avatar bones, see `references/en/udon_playerTracking.md`. It includes important notes and pitfalls for implementation.
# Persistence
If you need to save player-specific data (like high scores, inventory, or settings) across sessions or instances, refer to `references/en/udon_persistence.md`. This document explains how to use PlayerData and PlayerObjects for persistent storage.
# Loading (External Resources)
If you need to retrieve text/JSON data or images from external servers at runtime, see `references/en/udon_stringLoading.md` and `references/en/udon_imageLoading.md`. These documents explain how to use `VRCStringDownloader` and `VRCImageDownloader` with their respective callbacks and limitations.
# uGUI
If you need to implement player-interactable UI with Unity uGUI components such as Canvas, Button, Slider, Toggle, ScrollRect, or InputField/TMP_InputField, read `references/en/udon_uGUI.md`. This document explains how uGUI events must target the UdonBehaviour component and call `UdonBehaviour.SendCustomEvent` instead of directly assigning UdonSharp callbacks, how to read UI values from Inspector references, and which VRChat-specific Canvas and navigation settings are required.
# Creator Economy
If you need to handle in-game purchases, check product ownership, or utilize the VRChat Creator Economy SDK, refer to `references/en/udon_creatorEconomy.md`. This document explains how to use `UdonProduct`, the `Store` methods, and purchase events in UdonSharp.
Related in General
modeling-omnistudio-epc-catalog
IncludedSalesforce Industries CME EPC product-modeling skill for Product2-based catalog creation. Use when creating EPC products, configuring product attributes, building offer bundles with Product Child Items, or reviewing EPC DataPack JSON metadata for product catalog changes. TRIGGER when: user creates or updates Product2 EPC records, AttributeAssignment payloads, AttributeMetadata/AttributeDefaultValues, Offer bundles, or ProductChildItem relationships. DO NOT TRIGGER when: designing OmniScripts/FlexCards/Integration Procedures (use building-omnistudio-omniscript, building-omnistudio-flexcard, or building-omnistudio-integration-procedure), implementing Apex business logic (use generating-apex), or troubleshooting deployment pipelines (use deploying-metadata).
relationship-science-coach
IncludedUse this skill for direct, practical adult relationship coaching: couples conflict, repair, trust, marriage, dating, flirting, attachment patterns, emotional connection, sex, desire differences, eroticism, kink negotiation, affection, love languages, breakups, and long-term passion. Draw on Gottman, EFT and Hold Me Tight, attachment science, modern sex research, Perel, Nagoski, Kerner, Schnarch, Love and Stosny, and flexible love-language tools. Be concrete and low-hedge. Redirect only for imminent danger, abuse, coercive control, minors, non-consent, self-harm, stalking, or medical/legal/psychiatric decisions.
building-sf-integrations
IncludedSalesforce integration architecture and runtime plumbing with 120-point scoring. Use this skill to set up Named Credentials, External Credentials, External Services, REST/SOAP callout patterns, Platform Events, and Change Data Capture. TRIGGER when: user sets up Named Credentials, External Services, REST/SOAP callouts, Platform Events, CDC, or touches .namedCredential-meta.xml files. DO NOT TRIGGER when: Connected App/OAuth config (use configuring-connected-apps), Apex-only logic (use generating-apex), or data import/export (use handling-sf-data).
venue-templates
IncludedAccess comprehensive LaTeX templates, formatting requirements, and submission guidelines for major scientific publication venues (Nature, Science, PLOS, IEEE, ACM), academic conferences (NeurIPS, ICML, CVPR, CHI), research posters, and grant proposals (NSF, NIH, DOE, DARPA). This skill should be used when preparing manuscripts for journal submission, conference papers, research posters, or grant proposals and need venue-specific formatting requirements and templates.
let-fate-decide
IncludedDraws the 12 Houses of the Zodiac Tarot spread to inject entropy into planning when prompts are vague, ambiguous, or casually delegated. Interprets the spread to guide next steps. Use when the user says 'let fate decide', 'YOLO', 'whatever', 'idk', or other nonchalant phrases, makes Yu-Gi-Oh references, or when you are about to arbitrarily pick between multiple reasonable approaches. Prefer over ask-questions-if-underspecified when the user's tone is casual or playful rather than precision-seeking.
net-ops
IncludedCross-platform network troubleshooting (Windows, macOS, Linux) via local or remote shell. Use for: DNS broken, can't resolve hostnames, nslookup/dig works but apps fail, NRPT, WFP, scutil, /etc/resolver, systemd-resolved, /etc/resolv.conf, NetworkManager, VPN DNS leak residue (ProtonVPN/Mullvad/WireGuard/AnyConnect), AV/firewall blocking DNS or DoH, Tailscale DNS interaction, intermittent connectivity, remote diagnostics over SSH.