### Configure Local Player Settings (UdonSharp C#) Source: https://github.com/vrchat-community/udonsharp/blob/master/Tools/Docusaurus/docs/Examples.md This UdonSharp C# script allows for dynamic configuration of the local player's movement and physics settings. It uses `VRC.SDKBase.VRCPlayerApi` to set properties like jump impulse, walk speed, run speed, and gravity strength. The settings are applied once when the script starts, providing a way to customize player mechanics. ```C# using UnityEngine; using UdonSharp; using VRC.SDKBase; public class PlayerModSettings : UdonSharpBehaviour { VRCPlayerApi playerApi; [Header("Player Settings")] [SerializeField] float jumpImpulse = 3; [SerializeField] float walkSpeed = 2; [SerializeField] float runSpeed = 4; [SerializeField] float gravityStrengh = 1; void Start() { playerApi = Networking.LocalPlayer; playerApi.SetJumpImpulse(jumpImpulse); playerApi.SetWalkSpeed(walkSpeed); playerApi.SetRunSpeed(runSpeed); playerApi.SetGravityStrength(gravityStrengh); } } ``` -------------------------------- ### Install Project Dependencies with Yarn Source: https://github.com/vrchat-community/udonsharp/blob/master/Tools/Docusaurus/README.md This command installs all necessary project dependencies using the Yarn package manager. It should be run once after cloning the repository to prepare the environment. ```bash $ yarn ``` -------------------------------- ### Basic UdonSharp Behaviour Template in C# Source: https://github.com/vrchat-community/udonsharp/blob/master/Packages/com.vrchat.UdonSharp/Samples~/Utilities/ExampleUtilityTemplate.txt This snippet provides a minimal template for creating a new UdonSharp Behaviour script in Unity. It includes necessary `using` directives for VRChat SDK components and defines an empty class inheriting from `UdonSharpBehaviour`, ready for custom logic. This serves as a starting point for developing interactive elements in VRChat worlds. ```C# using UnityEngine; using VRC.SDK3.Components; using VRC.SDKBase; using VRC.Udon; namespace UdonSharp.Examples.Utilities { /// /// /// public class : UdonSharpBehaviour { } } ``` -------------------------------- ### Retrieve All Players in Instance (UdonSharp C#) Source: https://github.com/vrchat-community/udonsharp/blob/master/Tools/Docusaurus/docs/Examples.md This UdonSharp C# example demonstrates how to retrieve a list of all `VRCPlayerApi` objects currently present in the VRChat instance. It utilizes `VRCPlayerApi.GetPlayers` to populate an array with player data. The script then iterates through the array, logging each player's display name to the console, useful for player management or display. ```C# using UdonSharp; using UnityEngine; using VRC.SDKBase; public class GetPlayersExample : UdonSharpBehaviour { // World capacity is 10, so we create a new array with length of 20 (Hard cap) VRCPlayerApi[] players = new VRCPlayerApi[20]; void Start() { VRCPlayerApi.GetPlayers(players); foreach(VRCPlayerApi player in players) { if(player == null) continue; Debug.Log(player.displayName); } } } ``` -------------------------------- ### Get All Players in VRChat Instance with UdonSharp Source: https://github.com/vrchat-community/udonsharp/wiki/Examples This UdonSharp script illustrates how to retrieve a list of all players currently in the VRChat instance. It uses `VRCPlayerApi.GetPlayers` to populate an array with `VRCPlayerApi` objects and then iterates through it to log each player's display name to the console. ```cs using UdonSharp; using UnityEngine; using VRC.SDKBase; public class GetPlayersExample : UdonSharpBehaviour { // World capacity is 10, so we create a new array with length of 20 (Hard cap) VRCPlayerApi[] players = new VRCPlayerApi[20]; void Start() { VRCPlayerApi.GetPlayers(players); foreach(VRCPlayerApi player in players) { if(player == null) continue; Debug.Log(player.displayName); } } } ``` -------------------------------- ### UdonSharp Inter-Script Communication and Networking (UdonSharp C#) Source: https://github.com/vrchat-community/udonsharp/blob/master/Tools/Docusaurus/docs/Examples.md This comprehensive UdonSharp C# example showcases advanced concepts including inter-script communication and networked event handling. It demonstrates how to access variables and call methods on other `UdonSharpBehaviour` instances, both locally and across the network. The script illustrates sending custom events and `SendCustomNetworkEvent` to specific targets like 'All' or 'Owner', crucial for synchronized world logic. ```C# using UdonSharp; using UnityEngine; using VRC.SDKBase; using VRC.Udon.Common.Interfaces; namespace UdonSharpExample { public class Example : UdonSharpBehaviour { // UdonSharpBehaviour Class (Affects the Inspector) [SerializeField] AnotherExample anotherExample; void Start() { // Same as: anotherExample.GetProgramVariable("publicBoolean"); if(anotherExample.publicBoolean) { // Same as: anotherExample.SendCustomEvent("RunMethod"); anotherExample.RunMethod(); } } // VRChat Event public override void Interact() { // Same as: SendCustomEvent("DoStuff"); DoStuff(); } public void DoStuff() { // This will be sent to all clients and run locally on each one (including the one sending) SendCustomNetworkEvent(NetworkEventTarget.All, "NetworkEventStuff"); } public void NetworkEventStuff() { // Same as: anotherExample.SetProgramVariable("publicBoolean", false); anotherExample.publicBoolean = false; // Same as: anotherExample.SendCustomEvent("RunMethod"); anotherExample.RunMethod(); anotherExample.SendCustomNetworkEvent(NetworkEventTarget.Owner, "DoOwnerStuff"); } } } ``` -------------------------------- ### Start Local Development Server with Yarn Source: https://github.com/vrchat-community/udonsharp/blob/master/Tools/Docusaurus/README.md Initiates a local development server for the website, typically opening a browser window automatically. Changes made to the code are reflected live without requiring a server restart, facilitating rapid development. ```bash $ yarn start ``` -------------------------------- ### Adjust Player Movement Settings in UdonSharp Source: https://github.com/vrchat-community/udonsharp/wiki/Examples This UdonSharp script allows setting various player movement parameters like jump impulse, walk speed, run speed, and gravity strength. It utilizes `VRC.SDKBase.VRCPlayerApi` to modify the local player's properties when the script starts, providing custom player physics. ```cs using UnityEngine; using UdonSharp; using VRC.SDKBase; public class PlayerModSettings : UdonSharpBehaviour { VRCPlayerApi playerApi; [Header("Player Settings")] [SerializeField] float jumpImpulse = 3; [SerializeField] float walkSpeed = 2; [SerializeField] float runSpeed = 4; [SerializeField] float gravityStrengh = 1; void Start() { playerApi = Networking.LocalPlayer; playerApi.SetJumpImpulse(jumpImpulse); playerApi.SetWalkSpeed(walkSpeed); playerApi.SetRunSpeed(runSpeed); playerApi.SetGravityStrength(gravityStrengh); } } ``` -------------------------------- ### Advanced UdonSharp Script Communication Example Source: https://github.com/vrchat-community/udonsharp/wiki/Examples This comprehensive UdonSharp script demonstrates inter-script communication, including accessing program variables, sending custom events, and utilizing network events. It shows how one `UdonSharpBehaviour` can interact with another, synchronize actions across the network, and respond to VRChat events like `Interact()`. ```cs using UdonSharp; using UnityEngine; using VRC.SDKBase; using VRC.Udon.Common.Interfaces; namespace UdonSharpExample { public class Example : UdonSharpBehaviour { // UdonSharpBehaviour Class (Affects the Inspector) [SerializeField] AnotherExample anotherExample; void Start() { // Same as: anotherExample.GetProgramVariable("publicBoolean"); if(anotherExample.publicBoolean) { // Same as: anotherExample.SendCustomEvent("RunMethod"); anotherExample.RunMethod(); } } // VRChat Event public override void Interact() { // Same as: SendCustomEvent("DoStuff"); DoStuff(); } public void DoStuff() { // This will be sent to all clients and run locally on each one (including the one sending) SendCustomNetworkEvent(NetworkEventTarget.All, "NetworkEventStuff"); } public void NetworkEventStuff() { // Same as: anotherExample.SetProgramVariable("publicBoolean", false); anotherExample.publicBoolean = false; // Same as: anotherExample.SendCustomEvent("RunMethod"); anotherExample.RunMethod(); anotherExample.SendCustomNetworkEvent(NetworkEventTarget.Owner, "DoOwnerStuff"); } } } ``` -------------------------------- ### Rotate Object Continuously (UdonSharp C#) Source: https://github.com/vrchat-community/udonsharp/blob/master/Tools/Docusaurus/docs/Examples.md This UdonSharp C# example demonstrates how to make a GameObject continuously rotate around its Y-axis. It utilizes the `Update` method to apply rotation based on `Time.deltaTime`, ensuring frame-rate independent movement. This is a fundamental example for continuous object manipulation in VRChat worlds. ```C# using UnityEngine; using UdonSharp; public class RotatingCubeBehaviour : UdonSharpBehaviour { private void Update() { transform.Rotate(Vector3.up, 90f * Time.deltaTime); } } ``` -------------------------------- ### Teleport Local Player to Target (UdonSharp C#) Source: https://github.com/vrchat-community/udonsharp/blob/master/Tools/Docusaurus/docs/Examples.md This UdonSharp C# script provides functionality to teleport the local player to a designated target position and rotation. Upon interaction, it uses `Networking.LocalPlayer.TeleportTo` to instantly move the player. A `SerializeField` allows developers to easily assign the target `Transform` in the Unity editor. ```C# using UdonSharp; using UnityEngine; using VRC.SDKBase; public class TeleportPlayer : UdonSharpBehaviour { [SerializeField] Transform targetPosition; public override void Interact() { Networking.LocalPlayer.TeleportTo(targetPosition.position, targetPosition.rotation, VRC_SceneDescriptor.SpawnOrientation.Default, false); } } ``` -------------------------------- ### Default Udon Sharp Script Template (C#) Source: https://github.com/vrchat-community/udonsharp/wiki/Configuration This is the default C# template used when creating new Udon Sharp scripts. It includes common namespaces like UdonSharp, UnityEngine, VRC.SDKBase, and VRC.Udon, and defines a class inheriting from `UdonSharpBehaviour` with a basic `Start()` method. The `` placeholder is automatically replaced with the file name provided during script creation. ```cs using UdonSharp; using UnityEngine; using VRC.SDKBase; using VRC.Udon; public class : UdonSharpBehaviour { void Start() { } } ``` -------------------------------- ### Full Custom Inspector Example for UdonSharpBehaviour Source: https://github.com/vrchat-community/udonsharp/wiki/Editor-Scripting A complete, runnable example showcasing a `UdonSharpBehaviour` and its corresponding custom editor. This snippet demonstrates proper use of preprocessor directives for editor-only code, `OnInspectorGUI` override, `Undo` system integration, and drawing custom fields alongside the default UdonSharp header. ```C# 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 } ``` -------------------------------- ### Complete UdonSharp Custom Inspector Implementation Example Source: https://github.com/vrchat-community/udonsharp/blob/master/Tools/Docusaurus/docs/Editor-Scripting.md This comprehensive C# example demonstrates a full `UdonSharpBehaviour` and its corresponding custom inspector. It showcases proper usage of `UNITY_EDITOR` and `!COMPILER_UDONSHARP` directives for editor-only code, how to draw the default UdonSharp header, and how to implement a custom field (a string) with `EditorGUI.BeginChangeCheck()` and `Undo.RecordObject()` for robust change tracking and undo functionality. ```C# 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 } ``` -------------------------------- ### Teleport Player to a Target Position in UdonSharp Source: https://github.com/vrchat-community/udonsharp/wiki/Examples This UdonSharp script demonstrates how to teleport the local player to a predefined target position and rotation. It uses the `Networking.LocalPlayer.TeleportTo` method within the `Interact()` event, allowing players to instantly move to a new location upon interaction. ```cs using UdonSharp; using UnityEngine; using VRC.SDKBase; public class TeleportPlayer : UdonSharpBehaviour { [SerializeField] Transform targetPosition; public override void Interact() { Networking.LocalPlayer.TeleportTo(targetPosition.position, targetPosition.rotation, VRC_SceneDescriptor.SpawnOrientation.Default, false); } } ``` -------------------------------- ### VRC.Udon.UdonBehaviour Class API and Usage Example Source: https://github.com/vrchat-community/udonsharp/wiki/VRChat-API Documentation for the UdonBehaviour class, which allows interaction with Udon programs. This includes properties and methods for sending custom events, managing program variables, and triggering serialization. An example demonstrates how to obtain an UdonBehaviour component. ```cs UdonBehaviour behaviour = (UdonBehaviour)GetComponent(typeof(UdonBehaviour)); ``` ```APIDOC class VRC.Udon.UdonBehaviour: Properties: DisableInteractive: bool Summary: Determines whether an object with an Interact event should accept pointer raycasts and show an interactable outline and tooltips. Methods: SendCustomEvent(eventName: string) -> void Summary: Runs a public method on the behaviour SendCustomNetworkEvent(target: NetworkEventTarget, eventName: string) -> void Summary: Runs a public method over the network SendCustomEventDelayedSeconds(eventName: string, delaySeconds: float, eventTiming: EventTiming) -> void Summary: Executes a custom event on the behaviour after a time delay, measured in seconds. SendCustomEventDelayedFrames(eventName: string, delayFrames: int, eventTiming: EventTiming) -> void Summary: Executes a custom event on the behaviour after a frame delay. GetProgramVariable(symbolName: string) -> object Summary: Get a variable from the behaviour SetProgramVariable(symbolName: string, value: object) -> void Summary: Sets a variable on the behaviour GetProgramVariableType(symbolName: string) -> Type Summary: Retrieves the type of the specified variable from the behaviour. RequestSerialization() -> void Summary: Triggers the serialization and transmission of any synced variable data to remote clients. This is typically used when a behaviour is set to manual syncing mode. ``` -------------------------------- ### Spinning Cube in UdonSharp Source: https://github.com/vrchat-community/udonsharp/wiki/Examples This C# UdonSharp script demonstrates how to create a simple rotating cube. It uses the `Update` method, which is called every frame, to continuously rotate the object around the Y-axis at a constant speed. ```cs using UnityEngine; using UdonSharp; public class RotatingCubeBehaviour : UdonSharpBehaviour { private void Update() { transform.Rotate(Vector3.up, 90f * Time.deltaTime); } } ``` -------------------------------- ### RecursiveMethod Attribute Usage Example Source: https://github.com/vrchat-community/udonsharp/wiki/UdonSharp Demonstrates applying the `[RecursiveMethod]` attribute to a C# method to allow it to safely call itself recursively within an UdonSharp behaviour, with a note on performance implications. ```C# [RecursiveMethod] int Factorial(int input) { if (input == 1) return 1; return input * Factorial(input - 1); } ``` -------------------------------- ### UdonSynced Attribute Usage Example Source: https://github.com/vrchat-community/udonsharp/wiki/UdonSharp Demonstrates how to use the `[UdonSynced]` attribute on public fields to enable network synchronization for variables in UdonSharp behaviours. Shows both basic boolean synchronization and linearly interpolated float synchronization. ```C# public class Example : UdonSharpBehaviour { [UdonSynced] public bool synchronizedBoolean; [UdonSynced(UdonSyncMode.Linear)] // This float will be linearly interpolated public float synchronizedFloat; } ``` -------------------------------- ### UdonBehaviourSyncMode Attribute Usage Example Source: https://github.com/vrchat-community/udonsharp/wiki/UdonSharp Illustrates how to apply the `[UdonBehaviourSyncMode]` attribute to an UdonSharp behaviour class to enforce a specific synchronization mode, such as manual updates for its synced variables. ```C# [UdonBehaviourSyncMode(BehaviourSyncMode.Manual)] public class Example : UdonSharpBehaviour { } ``` -------------------------------- ### Basic Interactable Object in UdonSharp Source: https://github.com/vrchat-community/udonsharp/wiki/Examples This UdonSharp script shows a simple interaction where an object becomes inactive when a player interacts with it. It overrides the `Interact()` method, which is automatically called by VRChat when a player clicks on the object this script is attached to. ```cs using UnityEngine; using UdonSharp; public class ClickMe: UdonSharpBehaviour { public override void Interact() { gameObject.SetActive(false); } } ``` -------------------------------- ### DefaultExecutionOrder Attribute Usage Example Source: https://github.com/vrchat-community/udonsharp/wiki/UdonSharp Shows how to use the `[DefaultExecutionOrder]` attribute to specify the script execution order for an UdonSharp behaviour relative to others, affecting when Update, LateUpdate, and FixedUpdate methods are called. ```C# [DefaultExecutionOrder(0)] public class Example : UdonSharpBehaviour { } ``` -------------------------------- ### Networking Class API Reference Source: https://github.com/vrchat-community/udonsharp/blob/master/Tools/Docusaurus/docs/VRChat-API.md A static class providing network-related properties for VRChat SDK, such as determining if the local player is the instance master, getting the current player, and checking network readiness. ```APIDOC class VRC.SDKBase.Networking: Properties: IsMaster: bool Summary: Returns if the local player is the instance master LocalPlayer: VRCPlayerApi Summary: Returns the current player IsNetworkSettled: bool Summary: Returns true if the network is ready ``` -------------------------------- ### UdonSharp Rotating Cube Example Source: https://github.com/vrchat-community/udonsharp/blob/master/Tools/Docusaurus/docs/index.md This C# code snippet demonstrates a basic UdonSharpBehaviour script that rotates the attached GameObject by 90 degrees per second around the Y-axis. It utilizes the `Update` method for continuous rotation. ```C# using UnityEngine; using UdonSharp; public class RotatingCubeBehaviour : UdonSharpBehaviour { private void Update() { transform.Rotate(Vector3.up, 90f * Time.deltaTime); } } ``` -------------------------------- ### Get UdonSharp Components In Children Source: https://github.com/vrchat-community/udonsharp/blob/master/Tools/Docusaurus/docs/Editor-Scripting.md This example illustrates how to retrieve all UdonSharpBehaviour components of a specific type (`MyComponentType`) located on the children of a given GameObject. It uses the `GetUdonSharpComponentsInChildren()` extension method, which is the UdonSharp equivalent of Unity's `GetComponentsInChildren`. ```cs GameObject sourceGameObject = ... // Get some game object from somewhere here MyComponentType[] myComponents = sourceGameObject.GetUdonSharpComponentsInChildren(); ``` -------------------------------- ### Hide Object on Interact (UdonSharp C#) Source: https://github.com/vrchat-community/udonsharp/blob/master/Tools/Docusaurus/docs/Examples.md This simple UdonSharp C# example illustrates how to respond to player interaction with a GameObject. By overriding the `Interact` method, the script causes the GameObject to become inactive (`gameObject.SetActive(false)`) when a player clicks on it. This is a common pattern for interactive elements in VRChat. ```C# using UnityEngine; using UdonSharp; public class ClickMe: UdonSharpBehaviour { public override void Interact() { gameObject.SetActive(false); } } ``` -------------------------------- ### Build Static Website Content with Yarn Source: https://github.com/vrchat-community/udonsharp/blob/master/Tools/Docusaurus/README.md Generates static content for the website into the `build` directory. The output is a set of static files that can then be served by any static content hosting service, ready for deployment. ```bash $ yarn build ``` -------------------------------- ### VRCPlayerApi Methods Reference Source: https://github.com/vrchat-community/udonsharp/blob/master/Tools/Docusaurus/docs/VRChat-API.md Detailed reference for all methods available in the VRCPlayerApi, including static methods, return types, method names, parameters, and a summary of their functionality for UdonSharp development. ```APIDOC VRCPlayerApi: IsPlayerGrounded() -> bool: Returns if the player is on the ground or not static GetPlayerId(player: VRCPlayerApi) -> int: Returns the players instance id static GetPlayerById(playerId: int) -> VRCPlayerApi: Returns the player with the given id static GetPlayerCount() -> int: Returns the player count for the instance static GetPlayers(players: VRCPlayerApi[]) -> VRCPlayerApi[]: Populates and returns an array with the current players in the instance. The array parameter must be preallocated with at least VRCPlayerApi.GetPlayerCount elements. See example IsOwner(obj: GameObject) -> bool: Shows if the player is the owner of a gameObject with a UdonBehaviour on it GetTrackingData(tt: TrackingDataType) -> TrackingData: Returns the tracking data for the specified type GetBonePosition(bone: HumanBodyBones) -> Vector3: Return position data for the given bone GetBoneRotation(bone: HumanBodyBones) -> Quaternion: Return rotation data for the given bone TeleportTo(teleportPos: Vector3, teleportRot: Quaternion) -> void: Teleports the player to the position with rotation TeleportTo(teleportPos: Vector3, teleportRot: Quaternion, teleportOrientation: SpawnOrientation) -> void: Teleports the player to the position, rotation, and the spawn orientation TeleportTo(teleportPos: Vector3, teleportRot: Quaternion, teleportOrientation: SpawnOrientation, lerpOnRemote: bool) -> void: Teleports the player to the position, rotation, the spawn orientation, and if you want to lerp on remote EnablePickup(enable: bool) -> void: Set if the player can use pickups or not (*Need Testing*) SetPlayerTag(tagName: string, tagValue: string) -> void: Assigns a value to the tag for the player. Returns null if the tag has not been assigned. Note that player tags are not synchronized to remote clients. GetPlayerTag(tagName: string) -> string: Returns the value of the given tag for the player. Assign a value of null to clear the tag. ClearPlayerTags() -> void: Clears the tags on the given player SetRunSpeed(speed: float) -> void: Sets the player run speed SetWalkSpeed(speed: float) -> void: Sets the players walk speed SetJumpImpulse(impulse: float) -> void: Sets players jump impulse SetGravityStrength(strength: float) -> void: Sets the players gravity SetStrafeSpeed(speed: float) -> void: Sets the player's strafe speed. The default strafe speed is 2.0f. GetRunSpeed() -> float: Returns the current run speed value GetWalkSpeed() -> float: Returns the current walk speed value GetJumpImpulse() -> float: Returns the current jump impulse value GetGravityStrength() -> float: Returns the current gravity value GetStrafeSpeed() -> float: Returns the player's current strafe speed. IsUserInVR() -> bool: Returns if the current user is in VR UseLegacyLocomotion() -> void: Sets the locomotion to the old system Immobilize(immobile: bool) -> void: Prevents user from moving UseAttachedStation() -> void: Sits the players down on the station (Requires VRC_Station on the same gameObject) SetVelocity(velocity: Vector3) -> void: Sets the players velocity GetVelocity() -> Vector3: Returns the player velocity GetPosition() -> Vector3: Returns the player position GetRotation() -> Quaternion: Returns the player rotation SetVoiceGain(gain: float) -> void: Add boost to the Player's voice in decibels, range 0-24 SetVoiceDistanceNear(near: float) -> void: The near radius, in meters, where volume begins to fall off. It is strongly recommended to leave the Near value at zero for realism and effective spatialization for user voices. In Meters, Range 0 - 1,000,000 ``` -------------------------------- ### Udon Sharp Project and Debugging Settings Source: https://github.com/vrchat-community/udonsharp/wiki/Configuration This section details the various configuration options available under `Edit > Project Settings > Udon Sharp`. It covers settings for controlling script compilation behavior, defining custom script templates, and enabling specific debugging features like inline code and client exception monitoring. ```APIDOC Udon Sharp Project Settings: Auto compile on modify: Description: Enables automatic compilation of Udon Sharp scripts when a file is modified and saved. Compile all script: Description: Triggers compilation of all Udon Sharp scripts whenever changes are detected in any U# script. Compile on focus: Description: Compiles Udon Sharp scripts only when the Unity editor gains focus and changes have been made to a script. Script template override: Description: Allows defining a custom template for new Udon Sharp scripts by dragging a script into the designated field. Placeholder: (Replaced with the file name to set the class name dynamically). Debugging Settings: Debug build: Description: Controls the enabling or disabling of 'Inline Code' and 'Listen for client exceptions' debugging features. Inline Code: Description: Includes the C# inline code directly in the generated assembly code for debugging purposes. Listen for client exceptions: Description: Monitors the VRChat client's output log for exceptions and attempts to match them against scripts within the project. ``` -------------------------------- ### Deploy Website via SSH with Yarn Source: https://github.com/vrchat-community/udonsharp/blob/master/Tools/Docusaurus/README.md Deploys the website using SSH. This command is a convenient way to build the website and push the generated content to a remote server or a `gh-pages` branch, especially when using GitHub Pages for hosting. ```bash $ USE_SSH=true yarn deploy ``` -------------------------------- ### Overview of UdonSharp Attributes Source: https://github.com/vrchat-community/udonsharp/blob/master/Tools/Docusaurus/docs/UdonSharp.md A comprehensive list of attributes supported in UdonSharp, including Unity's built-in attributes and UdonSharp-specific ones, providing a quick reference to available functionalities. ```APIDOC UdonSharp Attributes: Header HideInInspector NonSerialized SerializeField Space Tooltip ColorUsage GradientUsage TextArea UdonSynced DefaultExecutionOrder UdonBehaviourSyncMode RecursiveMethod FieldChangeCallback ``` -------------------------------- ### VRCPlayerApi Methods Reference Source: https://github.com/vrchat-community/udonsharp/wiki/VRChat-API Detailed documentation for the VRCPlayerApi methods, including their purpose, parameters, return types, and whether they are static. These methods provide core functionalities for managing player interactions and properties in UdonSharp. ```APIDOC VRCPlayerApi: Methods: IsPlayerGrounded(): bool Summary: Returns if the player is on the ground or not static GetPlayerId(player: VRCPlayerApi): int Summary: Returns the players instance id Parameters: player: VRCPlayerApi static GetPlayerById(playerId: int): VRCPlayerApi Summary: Returns the player with the given id Parameters: playerId: int static GetPlayerCount(): int Summary: Returns the player count for the instance static GetPlayers(players: VRCPlayerApi[]): VRCPlayerApi[] Summary: Populates and returns an array with the current players in the instance. The array parameter must be preallocated with at least VRCPlayerApi.GetPlayerCount elements. See example Parameters: players: VRCPlayerApi[] IsOwner(obj: GameObject): bool Summary: Shows if the player is the owner of a gameObject with a UdonBehaviour on it Parameters: obj: GameObject GetTrackingData(tt: TrackingDataType): TrackingData Summary: Returns the tracking data for the specified type Parameters: tt: TrackingDataType GetBonePosition(bone: HumanBodyBones): Vector3 Summary: Return position data for the given bone Parameters: bone: HumanBodyBones GetBoneRotation(bone: HumanBodyBones): Quaternion Summary: Return rotation data for the given bone Parameters: bone: HumanBodyBones TeleportTo(teleportPos: Vector3, teleportRot: Quaternion): void Summary: Teleports the player to the position with rotation Parameters: teleportPos: Vector3 teleportRot: Quaternion TeleportTo(teleportPos: Vector3, teleportRot: Quaternion, teleportOrientation: SpawnOrientation): void Summary: Teleports the player to the position, rotation, and the spawn orientation Parameters: teleportPos: Vector3 teleportRot: Quaternion teleportOrientation: SpawnOrientation TeleportTo(teleportPos: Vector3, teleportRot: Quaternion, teleportOrientation: SpawnOrientation, lerpOnRemote: bool): void Summary: Teleports the player to the position, rotation, the spawn orientation, and if you want to lerp on remote Parameters: teleportPos: Vector3 teleportRot: Quaternion teleportOrientation: SpawnOrientation lerpOnRemote: bool EnablePickup(enable: bool): void Summary: Set if the player can use pickups or not (*Need Testing*) Parameters: enable: bool SetPlayerTag(tagName: string, tagValue: string): void Summary: Assigns a value to the tag for the player. Returns null if the tag has not been assigned. Note that player tags are not synchronized to remote clients. Parameters: tagName: string tagValue: string GetPlayerTag(tagName: string): string Summary: Returns the value of the given tag for the player. Assign a value of null to clear the tag. Parameters: tagName: string ClearPlayerTags(): void Summary: Clears the tags on the given player SetRunSpeed(speed: float): void Summary: Sets the player run speed Parameters: speed: float SetWalkSpeed(speed: float): void Summary: Sets the players walk speed Parameters: speed: float SetJumpImpulse(impulse: float): void Summary: Sets players jump impulse Parameters: impulse: float SetGravityStrength(strength: float): void Summary: Sets the players gravity Parameters: strength: float SetStrafeSpeed(speed: float): void Summary: Sets the player's strafe speed. The default strafe speed is 2.0f. Parameters: speed: float GetRunSpeed(): float Summary: Returns the current run speed value GetWalkSpeed(): float Summary: Returns the current walk speed value GetJumpImpulse(): float Summary: Returns the current jump impulse value GetGravityStrength(): float Summary: Returns the current gravity value GetStrafeSpeed(): float Summary: Returns the player's current strafe speed. IsUserInVR(): bool Summary: Returns if the current user is in VR UseLegacyLocomotion(): void Summary: Sets the locomotion to the old system Immobilize(immobile: bool): void Summary: Prevents user from moving Parameters: immobile: bool UseAttachedStation(): void Summary: Sits the players down on the station (Requires VRC_Station on the same gameObject) SetVelocity(velocity: Vector3): void Summary: Sets the players velocity Parameters: velocity: Vector3 GetVelocity(): Vector3 Summary: Returns the player velocity GetPosition(): Vector3 Summary: Returns the player position GetRotation(): Quaternion Summary: Returns the player rotation SetVoiceGain(gain: float): void Summary: Add boost to the Player's voice in decibels, range 0-24 Parameters: gain: float SetVoiceDistanceNear(near: float): void Summary: The near radius, in meters, where volume begins to fall off. It is strongly recommended to leave the Near value at zero for realism and effective spatialization for user voices. In Meters, Range 0 - 1,000,000 Parameters: near: float ``` -------------------------------- ### Get UdonBehaviour Component in C# Source: https://github.com/vrchat-community/udonsharp/blob/master/Tools/Docusaurus/docs/VRChat-API.md Demonstrates how to retrieve an UdonBehaviour component from a GameObject using `GetComponent` in C#. Note that direct generic `GetComponent()` is not supported for UdonBehaviour. ```cs UdonBehaviour behaviour = (UdonBehaviour)GetComponent(typeof(UdonBehaviour)); ``` -------------------------------- ### VRChat Networking Utility Static Methods Source: https://github.com/vrchat-community/udonsharp/wiki/VRChat-API Documentation for static utility methods related to VRChat networking, including ownership management, object destruction, and server time retrieval. These methods provide common functionalities for interacting with networked objects and time synchronization. ```APIDOC Static Methods: IsOwner(player: VRCPlayerApi, obj: GameObject) -> bool Summary: Returns if the given player is the owner over the object IsOwner(obj: GameObject) -> bool Summary: Returns if the local player is the owner of the object GetOwner(obj: GameObject) -> VRCPlayerApi Summary: Returns the owner of the given object SetOwner(player: VRCPlayerApi, obj: GameObject) -> void Summary: Sets the provided player as the owner of the object IsObjectReady(obj: GameObject) -> bool Summary: Returns if the object is ready Destroy(obj: GameObject) -> void Summary: Destroys the given object GetUniqueName(obj: GameObject) -> string Summary: (No summary provided) GetNetworkDateTime() -> DateTime Summary: (No summary provided) GetServerTimeInSeconds() -> double Summary: Returns the current server time in seconds. GetServerTimeInMilliseconds() -> int Summary: Returns the current server time in milliseconds. CalculateServerDeltaTime(timeInSeconds: double, previousTimeInSeconds: double) -> double Summary: Calculates the difference between two server time stamps as returned by `GetServerTimeInSeconds()`. ``` -------------------------------- ### VRCInstantiate Method Source: https://github.com/vrchat-community/udonsharp/wiki/VRChat-API Provides a static method to create a local, non-synced copy of a GameObject, mirroring Unity's Object.Instantiate functionality. ```APIDOC VRCInstantiate: VRCInstantiate(original: GameObject) -> GameObject original: The GameObject to instantiate. Returns: A local, non-synced copy of the original GameObject. See Unity's Object.Instantiate for more information. ``` -------------------------------- ### Basic UdonSharp Behaviour Template in C# Source: https://github.com/vrchat-community/udonsharp/blob/master/Packages/com.vrchat.UdonSharp/Tests~/TestScripts/TestScriptTemplate.txt This snippet provides a foundational C# template for creating UdonSharp behaviours in Unity. It includes necessary using directives for UdonSharp, UnityEngine, VRC.SDKBase, and VRC.Udon, a class definition inheriting from `UdonSharpBehaviour`, and a placeholder method `ExecuteTests()` for integration testing. ```C# using UdonSharp; using UnityEngine; using VRC.SDKBase; using VRC.Udon; namespace UdonSharp.Tests { [AddComponentMenu("Udon Sharp/Tests/")] public class : UdonSharpBehaviour { [System.NonSerialized] public IntegrationTestSuite tester; public void ExecuteTests() { } } } ``` -------------------------------- ### VRCPickup API Reference Source: https://github.com/vrchat-community/udonsharp/blob/master/Tools/Docusaurus/docs/VRChat-API.md API documentation for the `VRCPickup` component, which enables objects to be picked up and held by players. It outlines various properties controlling pickup behavior, such as momentum transfer, grip, and interaction text, along with methods for dropping the object and generating haptic feedback. ```APIDOC class VRC.SDK3.Components.VRCPickup class VRC.SDKBase.VRC_Pickup Description: A component used to allow objects to be picked up and held. Properties: MomentumTransferMethod: ForceMode - This defines how the collision force will be added to the other object which was hit, using `Rigidbody.AddForceAtPosition`. Note that the force will only be added if `AllowCollisionTransfer` is on. DisallowTheft: bool - If other users are allowed to take the pickup out of some else's grip. ExactGun: Transform - The position object will be held if set to Exact Gun. ExactGrip: Transform - The position object will be held if set to Exact Grip. allowManipulationWhenEquipped: bool - Should the user be able to manipulate the pickup while the pickup is held if using a controller. orientation: PickupOrientation - What way the object will be held. AutoHold: AutoHoldMode - Should the pickup remain in the users hand after they let go of the grab button. InteractionText: string - Tooltip text that is displayed when holding the pickup. UseText: string - Tooltip text that is displayed when hovering over the pickup. ThrowVelocityBoostMinSpeed: float - How fast the object needs to move to be thrown. ThrowVelocityBoostScale: float - How much throwing should scale, higher = faster thrown while lower means slower throw speed. pickupable: bool - Determines whether you can pickup the object. proximity: float - The maximum distance a player can be away from a pickup to interact with it. currentPlayer: VRCPlayerApi - The player that is currently holding the pickup. IsHeld: bool - Determines whether the pickup is currently being held by a player. currentHand: PickupHand - The hand that the player is holding the pickup with. Methods: Drop(): void - Drops the pickup if it is being held by a player. Drop(instigator: VRCPlayerApi): void - Drops the pickup if it is being held by a player. Note that the pickup will only drop if `instigator` is the player who is holding the pickup. GenerateHapticEvent(duration: float, amplitude: float, frequency: float): void - Plays haptic feedback on the player's controller. Default values are duration: 0.25, amplitude: 0.5, frequency: 0.5. PlayHaptics(): void - Plays haptic feedback on the player's controller. ``` -------------------------------- ### Basic UdonSharpBehaviour Class Template Source: https://github.com/vrchat-community/udonsharp/blob/master/Packages/com.vrchat.UdonSharp/Samples~/Tutorials/ExampleTutorialTemplate.txt This snippet provides a minimal template for creating a new UdonSharpBehaviour script in Unity for VRChat's Udon platform. It includes necessary using directives for Unity, VRChat SDK components, and Udon, along with an empty class definition inheriting from UdonSharpBehaviour, ready for custom logic. ```C# using UnityEngine; using VRC.SDK3.Components; using VRC.SDKBase; using VRC.Udon; namespace UdonSharp.Examples.Tutorials { /// /// /// public class : UdonSharpBehaviour { } } ``` -------------------------------- ### VRCPortalMarker Component API Source: https://github.com/vrchat-community/udonsharp/wiki/VRChat-API API documentation for the `VRCPortalMarker` component, used to create and manage portals to other rooms in VRChat. This component allows world creators to define destinations for players to easily travel between different instances or worlds. ```APIDOC VRCPortalMarker: class VRC.SDK3.Components.VRCPortalMarker / class VRC.SDKBase.VRC_PortalMarker A component used to create portals to other rooms. Properties: roomId: string - Room Id of the destination room. Methods: RefreshPortal(): void - Refreshes the portal displayed to the player. ``` -------------------------------- ### VRChat UdonSharp Networked Instantiation Source: https://github.com/vrchat-community/udonsharp/wiki/Networking-Tips-&-Tricks Addresses the current state of networked instantiation in Udon, noting that it is not natively supported and suggesting object-pooling as the primary workaround. ```APIDOC Concept: Networked Instantiation in VRChat Udon Status (2020-06-17): - Not networked. - Instantiated objects cannot be correctly synchronized. Workaround: - Object-pooling (more detailed guide needed). ``` -------------------------------- ### In-File Custom Editor with UdonSharp Compiler Exclusion Source: https://github.com/vrchat-community/udonsharp/blob/master/Tools/Docusaurus/docs/Editor-Scripting.md This example illustrates how to define a custom editor directly within the same C# script file as its associated `UdonSharpBehaviour`. It utilizes a combined preprocessor directive `!COMPILER_UDONSHARP && UNITY_EDITOR` to ensure the editor code is only active in the Unity Editor and is explicitly ignored by the UdonSharp compiler, preventing compilation errors for editor-specific features. ```C# public class CustomInspectorBehaviour : UdonSharpBehaviour { ... } #if !COMPILER_UDONSHARP && UNITY_EDITOR [CustomEditor(typeof(CustomInspectorBehaviour))] public class CustomInspectorEditor : Editor { ... } #endif ``` -------------------------------- ### Static Utility Methods for Object Ownership and Network Time Source: https://github.com/vrchat-community/udonsharp/blob/master/Tools/Docusaurus/docs/VRChat-API.md Documents static utility methods related to object ownership management, network time retrieval, and server time calculations within the VRChat UdonSharp SDK. ```APIDOC Static Methods: IsOwner(player: VRCPlayerApi, obj: GameObject): bool Summary: Returns if the given player is the owner over the object IsOwner(obj: GameObject): bool Summary: Returns if the local player is the owner of the object GetOwner(obj: GameObject): VRCPlayerApi Summary: Returns the owner of the given object SetOwner(player: VRCPlayerApi, obj: GameObject): void Summary: Sets the provided player as the owner of the object IsObjectReady(obj: GameObject): bool Summary: Returns if the object is ready Destroy(obj: GameObject): void Summary: Destroys the given object GetUniqueName(obj: GameObject): string GetNetworkDateTime(): DateTime GetServerTimeInSeconds(): double Summary: Returns the current server time in seconds. GetServerTimeInMilliseconds(): int Summary: Returns the current server time in milliseconds. CalculateServerDeltaTime(timeInSeconds: double, previousTimeInSeconds: double): double Summary: Calculates the difference between two server time stamps as returned by `GetServerTimeInSeconds()`. ``` -------------------------------- ### VRChat UdonSharp Networked Events (Photon RPCs) Source: https://github.com/vrchat-community/udonsharp/wiki/Networking-Tips-&-Tricks Details how networked events (Photon RPCs) work in Udon, their targeting limitations, and workarounds for specific player targeting. Also addresses known issues regarding network blocking and race conditions with synced variables. ```APIDOC Concept: Networked Events (Photon RPCs) in VRChat Udon Description: - Sent to specified UdonBehaviour. - Target: All players OR owner of GameObject. - Limitation: No direct way to target specific player. Workaround 1 (Complex): - Give each player ownership of a GameObject. - Use Networking.GetOwner(GameObject) to find target UdonBehaviour. Workaround 2 (Tricky): - Use synced variable (string for displayName or int for playerID) to indicate target player. - Issue: Events often arrive before synced variable updates. Known Issues: - Sending too many events can "block" the Network. - Events processed faster than synced variable updates; can cause race conditions if variable is updated then event sent. - Mitigation: Wait after variable update or detect change locally. API References: - Networking.GetOwner(GameObject targetGameObject) ```