This doc covers Networking Components, Properties and Events you can use in your Udon Programs.
Special properties you can get from Networking:
IsClogged - returns true if there is too much data trying to get out. You can use this to hold off some operations or adjust your logic.
IsInstanceOwner - returns true if the Local Player is the one who created the instance. False when in Build & Test and Unity Playmode.
IsMaster - returns true if the Local Player is the 'Master' - either the first person who entered the instance or the person automatically designated as Master when the last Master left. Old logic, not recommended for use. IsOwner or IsInstanceOwner are better.
IsNetworkSettled - returns true once all the data in the instance has been deserialized and applied, and it's ready for use.
LocalPlayer - returns the VRC Player API object of the local player. Will be null in the editor - use Utilities.IsValid to easily branch your logic on this.
These are the events available as part of the Networking system to control how your data is synced.
This event triggers just before serialized data will be sent out, it's a good place to set synced variables that you want to be updated for other players.
This event triggers when sync data has been transformed from bytes back into usable variables. It does not tell you which data has been updated, but serves as a jumping-off point to either update everything that watches synced variables, or a place to check new data against old data and make specific updates.
This event triggers just after an attempt was made to send serialized data. It returns a SerializationResult struct with a 'success' bool and 'byteCount' int with the number of bytes sent.
This event is deprecated - use the typical OnEnabled event if you want to do something when an object is 'Spawned' from the pool.
This event is triggered when someone has requested to take ownership. It includes the Player Objects for the Requester and the Requested Owner. To approve or deny the change, set a boolean value into a "Set Return Value" node. This logic runs locally on both the requester and the owner, so be aware that disagreements in logic between the two will cause a desync. This is most likely to be expressed by the ownership transfer being unexpectedly rejected by the owner.
This event is triggered for everyone in the instance when an objects ownership is changed, and includes the Player Object for the new owner.
This component will automatically sync the Transform (position, rotation scale) and Rigidbody (physics) of the object you put it on. It has a few special methods and properties you can access:
Trigger this when you want to teleport the object - the changes you make this frame will be applied without smoothing.
Changes the gravity state, usually handled by the Rigidbody of the object but controlled here for sync purposes.
Changes the kinematic state, usually handled by the Rigidbody of the object but controlled here for sync purposes. When the kinematic state is on, this Rigidbody ignores forces, collisions and joints.
Teleports this object back to its starting Position and Rotation, and removes its Velocities.
Specifically, it sets DiscontinuityHint to true to make the following changes instant instead of smooth. Then it:
- sets transform.position to initial position
- sets transform.rotation to initial rotation
If the object has a rigidbody:
- sets the rigidbody.velocity to Vector3.zero
- sets the rigidbody.angularVelocity Vector3.zero
- sets the rigidbody.position to initial position
- sets the rigidbody.rotation to initial rotation
VRC Object Pool provides a lightweight method of managing an array of game objects. The pool will manage and synchronize the active state of each object it holds.
To make an object active, the Owner of the pool triggers the TryToSpawn node, which will return the object that was made active, or a null object if none are available. Objects may be returned to the pool by the pool's owner, and automatically disabled, via the Return node.
Late joiners will have the objects automatically made active or inactive where appropriate.
Updated 3 months ago