### VRChat Client Path Examples Source: https://creators.vrchat.com/worlds/udon/using-build-test These are default installation paths for the VRChat client on different platforms. Ensure your VRChat executable is correctly linked in the VRChat SDK settings. ```text C:\Program Files (x86)\Steam\steamapps\common\VRChat\VRChat.exe ``` ```text C:\Program Files\Oculus\Software\Software\vrchat-vrchat\VRChat.exe ``` ```text C:\Viveport\ViveApps\469fbcbb-bfde-40b5-a7d4-381249d387cd\1597468388\VRChat.exe ``` -------------------------------- ### Basic Markdown Example Source: https://creators.vrchat.com/contribute/syntax A simple example demonstrating basic Markdown syntax for a documentation page, including a title and text. ```markdown # Example page This is an example page with a title and some text. ``` -------------------------------- ### UdonSharp Camera Info Display Example Source: https://creators.vrchat.com/worlds/udon/vrc-graphics/vrc-camera-settings This example demonstrates how to use the `OnVRCCameraSettingsChanged` event to update UI text with camera resolution, FOV, and frame count. It initializes the display in `Start` and updates it when camera settings change. Ensure the `info` TextMeshProUGUI field is assigned in the inspector. ```csharp using TMPro; using UdonSharp; using UnityEngine; using UnityEngine.UI; using VRC.SDK3.Rendering; public class CameraInfoDisplay : UdonSharpBehaviour { [SerializeField] private TextMeshProUGUI info; void Start() { // call it once to initialize OnVRCCameraSettingsChanged(VRCCameraSettings.ScreenCamera); Debug.Log($ ``` -------------------------------- ### Udon Parameter Size Examples Source: https://creators.vrchat.com/worlds/udon/networking/events Illustrates the byte size of various data types and collections when used as Udon network event parameters, showing which examples fit within a single internal event and which require multiple. ```csharp // fits into 1 internal event: int x = 0; // = 4 bytes, sizeof(int) Vector3 v = Vector3.zero; // = 12 bytes, sizeof(float) * 3 new string('x', 400); // = 400 bytes, UTF-8 encoded "うどんは美味しい"; // = 24 bytes, UTF-8 encoded with non-ASCII characters new char[128]; // = 256 bytes, UTF-16 (following C# spec) new byte[1024]; // = 1024 bytes // requires more than 1 internal event: new byte[1025]; // = 1025 bytes, 2 events sent new byte[16 * 1024] // = 16384 bytes, 16 events sent, maximum allowed size new int[512]; // = 2048 bytes, sizeof(int) * 512, 2 events sent // string[] and VRCUrl[] are special cases: new string[2] { "test", "foobar" }; // = 18 bytes, 4 + 6 from UTF-8 encoded strings, 8 additional for a length value per array entry ( 2 * sizeof(int) ) ``` -------------------------------- ### Set and Get Dictionary Items using Bracket Syntax Source: https://creators.vrchat.com/worlds/udon/data-containers/data-dictionaries Use bracket syntax for concise setting and getting of dictionary items. This is suitable when you can guarantee the key's existence and the data type. ```csharp dictionary["A"] = 5; dictionary["B"] = 10; // This makes the assumption that A and B will always contain integers. // This is a safe assumption to make since we set them just above in a controlled environment. // If the data is coming from an external source, we shouldn't make these assumptions! int sum = dictionary["A"].Int + dictionary["B"].Int; ``` -------------------------------- ### ImageDownload Script Setup Source: https://creators.vrchat.com/worlds/examples/image-loading Use the ImageDownload script by adding it to a GameObject with an UdonBehaviour component. Assign a Material to apply the downloaded texture. ```csharp using UdonSharp; using VRC.SDKBase; using UnityEngine; public class ImageDownload : UdonSharpBehaviour { public Material TargetMaterial; public TextureInfo TextureSettings; public override void Interact() { // Example: Download image on interaction DownloadImage("https://example.com/image.png"); } public void DownloadImage(string url) { // Logic to download image and apply to TargetMaterial // This is a placeholder for the actual implementation Debug.Log("Downloading image from: " + url); } // Placeholder for TextureInfo struct if it exists in the SDK public struct TextureInfo { // Define texture settings here if applicable } } ``` -------------------------------- ### Set and Get Values using Shorthand Bracket Syntax Source: https://creators.vrchat.com/worlds/udon/data-containers/data-lists Utilize bracket syntax (`list[index]`) for concise setting and getting of DataList items. This method is efficient but not entirely safe; use it only when you can guarantee the data's existence and type, typically in controlled environments where values were just set. ```csharp list[0] = 5; list[1] = 10; // This makes the assumption that index 0 and 1 will always contain integers. // This is a safe assumption to make since we set them just above in a controlled environment. // If the data is coming from an external source, we shouldn't make these assumptions! int sum = list[0].Int + list[1].Int; ``` -------------------------------- ### VRC Camera Dolly Hierarchy Example Source: https://creators.vrchat.com/worlds/components/vrc_cameradolly Illustrates the expected nesting of GameObjects with VRC Camera Dolly components for defining an animation. ```text Animation ├── Path 1 │ ├── Point 1 │ └── Point 2 └── Path 2 ├── Point 1 ├── Point 2 ├── Point 3 └── Point 4 ``` -------------------------------- ### Udon Behaviour Communication Source: https://creators.vrchat.com/worlds/examples/udon Demonstrates inter-behaviour communication using variables and custom network events. This example shows sending events between UdonBehaviours. ```csharp using UdonSharp; using UnityEngine; using VRC.Udon.Common.Interfaces; public class SomeExample : UdonSharpBehaviour { [SerializeField] private SomeOtherExample otherBehaviour; void Start() { if(otherBehaviour.somePublicBoolean) { otherBehaviour.SomeCustomEvent(); } } public override void Interact() { DoStuff(); } private void DoStuff() { SendCustomNetworkEvent(NetworkEventTarget.All, nameof(DoNetworkEventStuff)); } public void DoNetworkEventStuff() { otherBehaviour.somePublicBoolean = false; otherBehaviour.SomeCustomEvent(); otherBehaviour.SendCustomNetworkEvent(NetworkEventTarget.Owner, nameof(DoOwnerStuff)); } } ``` -------------------------------- ### Create and Use VRCImageDownloader Source: https://creators.vrchat.com/worlds/udon/image-loading Instantiate VRCImageDownloader to download images from a URL. This example shows how to create a downloader, specify a URL, and optionally a material to apply the texture to. It also demonstrates how to handle download events. ```UdonSharp using UdonSharp; using VRC.SDKBase; using VRC.Udon; using UnityEngine; public class ImageLoader : UdonSharpBehaviour { public VRCUrl imageUrl; public Material targetMaterial; private VRCImageDownloader imageDownloader; void Start() { imageDownloader = new VRCImageDownloader(); } public void DownloadImage() { if (imageDownloader == null) { imageDownloader = new VRCImageDownloader(); } // Download the image and apply it to the target material imageDownloader.DownloadImage(imageUrl, targetMaterial, this); } public override void OnImageDownloadSuccess(IVRCImageDownload download) { Debug.Log("Image downloaded successfully!"); // You can access the downloaded texture via download.Result } public override void OnImageDownloadError(IVRCImageDownload download, VRCImageDownloader.ErrorCode error) { Debug.LogError("Image download failed: " + error.ToString()); } void OnDestroy() { // Dispose of the downloader and its associated textures when the object is destroyed if (imageDownloader != null) { imageDownloader.Dispose(); imageDownloader = null; } } } ``` -------------------------------- ### Front Matter Example Source: https://creators.vrchat.com/contribute/syntax An example of front matter, which is optional data about a Markdown file used to control how Docusaurus presents the page. ```yaml --- unlisted: true --- ``` -------------------------------- ### Example Network ID Export Format Source: https://creators.vrchat.com/worlds/udon/networking/network-id-utility This is an example of the JSON format used when exporting network IDs. It maps network IDs to their corresponding scene hierarchy paths. ```JSON {"10":"/CubePickup", "11":"/Prefabs/SyncedPen"} ``` -------------------------------- ### Udon Runtime Error Example Source: https://creators.vrchat.com/worlds/udon/debugging-udon-projects This is an example of a Udon runtime error that might appear in VRChat logs. It indicates an exception occurred during Udon execution, causing the UdonBehaviour to halt. ```log 2020.08.28 17:40:51 Error - [UdonBehaviour] An exception occurred during Udon execution, this UdonBehaviour will be halted. VRC.Udon.VM.UdonVMException: An exception occurred in an UdonVM, execution will be halted. ---> VRC.Udon.VM.UdonVMException: An exception occurred during EXTERN to 'VRCSDK3VideoComponentsBaseBaseVRCVideoPlayer.__GetTime__SystemSingle'. ---> System.NullReferenceException: Object reference not set to an instance of an object. at VRC.SDK3.Internal.Video.Components.AVPro.AVProVideoPlayerInternal.GetTime () [0x00000] in <00000000000000000000000000000000>:0 at VRC.Udon.Wrapper.Modules.ExternVRCSDK3VideoComponentsBaseBaseVRCVideoPlayer.__GetTime__SystemSingle (VRC.Udon.Common.Interfaces.IUdonHeap heap, System.UInt32[] parameterAddresses) [0x00000] in <00000000000000000000000000000000>:0 ``` -------------------------------- ### UdonSharp Hello World Example Source: https://creators.vrchat.com/contribute/syntax A basic UdonSharp script that logs 'Hello, world!' to the console. This snippet is typically used within a TabItem for UdonSharp code. ```csharp private void Start() { Debug.Log("Hello, world!"); } ``` -------------------------------- ### Instantiate VRCImageDownloader Source: https://creators.vrchat.com/worlds/examples/image-loading Create a new VRCImageDownloader instance and store it in a variable to prevent garbage collection. This is essential for reusing the downloader across multiple image loads. ```csharp private VRCImageDownloader _imageDownloader; void Start() { // It's important to store the VRCImageDownloader as a variable, to stop it from being garbage collected! _imageDownloader = new VRCImageDownloader(); } ``` -------------------------------- ### Hook into Build Start Event Source: https://creators.vrchat.com/sdk/public-sdk-api Subscribe to the OnSdkBuildStart event to execute custom logic just before the SDK initiates the build process, after validations have passed. This allows for pre-build actions. ```csharp [InitializeOnLoadMethod] public static void RegisterSDKCallback() { VRCSdkControlPanel.OnSdkPanelEnable += AddBuildHook; } private static void AddBuildHook(object sender, EventArgs e) { if (VRCSdkControlPanel.TryGetBuilder(out var builder)) { builder.OnSdkBuildStart += OnBuildStarted; } } private static void OnBuildStarted(object sender, object target) { Debug.Log("Building " + ((GameObject) target).name); } ``` -------------------------------- ### Example Custom Inspector for UdonSharpBehaviour Source: https://creators.vrchat.com/worlds/udon/udonsharp/editorscripting A complete example of a custom inspector for `CustomInspectorBehaviour`. It includes necessary using statements, editor-only checks, drawing the default header, and custom field modification with undo support. ```csharp using UnityEngine; using VRC.SDK3.Components; using VRC.SDKBase; using VRC.Udon; #if !COMPILER_UDONSHARP && UNITY_EDITOR // These using statements must be wrapped in this check to prevent issues on builds using UnityEditor; using UdonSharpEditor; #endif namespace UdonSharp.Examples.Inspectors { /// /// Example behaviour that has a custom inspector /// public class CustomInspectorBehaviour : UdonSharpBehaviour { public string stringVal; private void Update() { Debug.Log($"CustomInspectorBehaviour: {stringVal}"); } } // Editor scripts must be wrapped in a UNITY_EDITOR check to prevent issues while uploading worlds. The !COMPILER_UDONSHARP check prevents UdonSharp from throwing errors about unsupported code here. #if !COMPILER_UDONSHARP && UNITY_EDITOR [CustomEditor(typeof(CustomInspectorBehaviour))] public class CustomInspectorEditor : Editor { public override void OnInspectorGUI() { // Draws the default convert to UdonBehaviour button, program asset field, sync settings, etc. if (UdonSharpGUI.DrawDefaultUdonSharpBehaviourHeader(target)) return; CustomInspectorBehaviour inspectorBehaviour = (CustomInspectorBehaviour)target; EditorGUI.BeginChangeCheck(); // A simple string field modification with Undo handling string newStrVal = EditorGUILayout.TextField("String Val", inspectorBehaviour.stringVal); if (EditorGUI.EndChangeCheck()) { Undo.RecordObject(inspectorBehaviour, "Modify string val"); inspectorBehaviour.stringVal = newStrVal; } } } #endif } ``` -------------------------------- ### SimulationTime Source: https://creators.vrchat.com/worlds/udon/players Gets the simulation time of a player. ```APIDOC ## SimulationTime ### Description The simulation time of a player. ### Method _float_ ### Parameters None ### Response - **float**: The simulation time of the player. ### Example ```csharp float simTime = player.SimulationTime; ``` ``` -------------------------------- ### FFmpeg Command for Web Optimization Source: https://creators.vrchat.com/worlds/udon/video-players Use the `-movflags +faststart` parameter with FFmpeg to optimize MP4 files for web streaming. This ensures videos can start playing before the entire file is downloaded. ```bash ffmpeg -i input.mp4 -movflags +faststart output.mp4 ``` -------------------------------- ### Store.GetPlayersWhoOwnProduct Source: https://creators.vrchat.com/economy/sdk/udon-documentation Gets all the players in the instance who own a certain product. ```APIDOC ## Store.GetPlayersWhoOwnProduct ### Description This method gets all the players in the instance who own a certain product. ### Input - `UdonProduct` or `IProduct`: Product that you want to check the ownership of. ### Output - `VRCPlayerApi[]`: An array of players in the instance that own this product. ``` -------------------------------- ### Implement IPreprocessCallbackBehaviour for Pre-Build Actions Source: https://creators.vrchat.com/sdk/build-pipeline-callbacks-and-interfaces Use this interface to execute custom code just before the build process begins. This is useful for making modifications to content before it's built and uploaded. Note that this does not bypass SDK validation; consider using IEditorOnly for scripts directly on the avatar being uploaded. ```csharp public void OnPreprocess() { } public int PreprocessOrder { get; } ``` -------------------------------- ### GetPlayer Source: https://creators.vrchat.com/worlds/udon/players/drones/drone-information Gets the owner of the Drone. Returns the owning player object. ```APIDOC ## GetPlayer ### Description Gets the owner of the Drone. ### Output * `VRCPlayerApi`: The owning player object. ``` -------------------------------- ### Download String Data with VRCStringDownloader Source: https://creators.vrchat.com/worlds/examples/image-loading Use VRCStringDownloader to fetch string data from a URL. This snippet demonstrates how to initiate the download, handle successful string loading by splitting the content into lines, and log errors if the download fails. The `IUdonEventReceiver` is cast to `this` to receive the download events. ```csharp private IUdonEventReceiver _udonEventReceiver; private string[] _captions; void Start() { // To receive Image and String loading events, 'this' is casted to the type needed _udonEventReceiver = (IUdonEventReceiver)this; // Captions are downloaded once. On success, OnImageLoadSuccess() will be called. VRCStringDownloader.LoadUrl(stringUrl, _udonEventReceiver); } public override void OnStringLoadSuccess(IVRCStringDownload result) { _captions = result.Result.Split('\n'); UpdateCaptionText(); } public override void OnStringLoadError(IVRCStringDownload result) { Debug.LogError($"Could not load string {result.Error}"); } ``` -------------------------------- ### Import and Use Tabs and TabItem Source: https://creators.vrchat.com/contribute/syntax Demonstrates how to import and utilize the Tabs and TabItem components for displaying code in different languages. Ensure the groupId is consistent for synchronization. ```javascript import Tabs from '@theme/Tabs'; import TabItem from '@theme/TabItem'; ![A screenshot of the Udon Graph.](/img/worlds/graph-helloworld.png) ```cs showLineNumbers private void Start() { Debug.Log("Hello, world!"); } ``` ``` -------------------------------- ### Basic Code Block Source: https://creators.vrchat.com/contribute/syntax A basic example of a code block for including UdonSharp code on a page. ```csharp // This is an example code block. Debug.Log("Hello, world!"); ``` -------------------------------- ### Launch VRChat with Watch Worlds Flag Source: https://creators.vrchat.com/worlds/udon/using-build-test Use this command-line argument to launch VRChat with world reloading enabled, allowing for faster testing cycles. This example includes various debugging and display options. ```bash VRChat.exe --watch-worlds --profile=0 --no-vr --enable-debug-gui --enable-sdk-log-levels --enable-udon-debug-logging -screen-width 1920 -screen-height 1080 ``` -------------------------------- ### IsDeployed Source: https://creators.vrchat.com/worlds/udon/players/drones/drone-information Get whether the Drone is deployed in the world. Returns a boolean indicating deployment status. ```APIDOC ## IsDeployed ### Description Get whether the Drone is deployed in the world. ### Output * `bool`: Whether the drone is deployed. ``` -------------------------------- ### Enable Udon Debugging via Steam Launch Options Source: https://creators.vrchat.com/worlds/udon/debugging-udon-projects Configure Steam launch options to always enable the Debug GUI and Udon Debugging for VRChat. This is a convenient way to ensure debugging tools are active. ```steam --enable-debug-gui --enable-udon-debug-logging ``` -------------------------------- ### TryGetRotation Source: https://creators.vrchat.com/worlds/udon/players/drones/drone-information Try to get the rotation of the Drone. Returns a boolean indicating success and the rotation via an out parameter. ```APIDOC ## TryGetRotation ### Description Try to get the rotation of the Drone. ### Out * `Quaternion rotation`: The rotation of the Drone in world space. ### Output * `bool`: indicates whether it was successful ``` -------------------------------- ### UdonSharp Example for VRCAsyncGpuReadback Source: https://creators.vrchat.com/worlds/udon/vrc-graphics/asyncgpureadback This UdonSharp script demonstrates how to make an asynchronous GPU readback request and handle its completion. It's suitable for scenarios requiring background texture data retrieval without blocking the main thread. ```csharp using UdonSharp; using UnityEngine; using VRC.SDK3.Rendering; using VRC.Udon.Common.Interfaces; public class AGPURB : UdonSharpBehaviour { public Texture texture; void Start() { VRCAsyncGPUReadback.Request(texture, 0, (IUdonEventReceiver)this); } public void OnAsyncGpuReadbackComplete(VRCAsyncGPUReadbackRequest request) { if (request.hasError) { Debug.LogError("GPU readback error!"); return; } else { var px = new Color32[texture.width * texture.height]; Debug.Log("GPU readback success: " + request.TryGetData(px)); Debug.Log("GPU readback data: " + px[0]); } } } ``` -------------------------------- ### GetRotation Source: https://creators.vrchat.com/worlds/udon/players/drones/drone-information Gets the rotation of the Drone in world space. Returns a Quaternion representing the drone's rotation. ```APIDOC ## GetRotation ### Description Gets the rotation of the Drone. ### Output * `Quaternion`: The drone's rotation in world space. ```