Skip to content

Misc Behaviours

orels1 edited this page Jul 22, 2020 · 25 revisions

A collection of small, general / single purpose built behaviours

Before using any of these behaviours, check the general usage guide.

How to read the docs

  • Parameters list describes all the public variables and settings exposed to you, some of them are UI only, so if you're planning to modify them via other udon behaviours - make sure to check the actual UdonBehaviour component on the same object.
  • Events list describes all the exposed custom events the component expects to recieve. Most things that are expected to be "Triggered" in some way usually have a Trigger event exposed. The full list of events can also be seen at the bottom of the behaviour UI with a convinience button for you to use while testing in editor.
  • Usage / Examples is a freeform section with some personal usage advice and other notes

Overall approach

You can generally split the things below into Triggers and Actions (plus some extras), one group captures player interactions in some way - the other performs some actions in response.

Most of the time you would add a bunch of Universal Action behaviours to the scene and then trigger them from all the different trigger behaviours listed on this page. But this system can also easily interact with other things in your world outside of Udon Toolkit! So don't feel limited by the Universal Action and use the Udon Events list with other behaviours to mix and match stuff.

Movement / Tracking

Universal Tracker

Tracks local player's Tracking Data source or a Bone transform and copies it over to the target transform

Parameters

  • Track Bone: Switches between tracking a Tracking Data source (Head/Hands) and tracking Bones
  • Bone: Only visible when Track Bone is checked. Specifies which Bone to track
  • Tracking Target: Only visible when Track Bone is unchecked. Specifies which Tracking Data target to use
  • Target Transform: Transform to copy the tracked Bone / Tracking Data position and rotation to
  • Track Position: Specifies whether the position should be copied
  • Track Rotation: Specifies whether the rotation should be copied
  • Tracking Correction: Allows to apply an extra X/Y/Z rotation to the transform after copying it over
  • Follow Main Camera: For editor use only. Makes the object follow the main camera, helpful for editor testing

Usage / Examples

The basic usage of this component is intended to be things like attaching objects to player's hands, head or both.


Lerped Follower

Makes an object follow another object with smooth interpolation

Parameters

  • Source Transform: The source of position and rotation to copy from
  • Target Transform: The target of position and rotation to copy to
  • Lerp Position: Specifies whether the position should be interpolated (smoothed) or instant
  • Lerp Rotation: Specifies whether the rotation should be interpolated (smoothed) or instant
  • Lerp Speed: A speed with which Target will achieve Source's position and rotation
  • Ignore Rotation: Specifies whether to copy rotation or completely ignore it

Usage / Examples

Generally good feeling lerp value for scene objects seems to be at around 5-15, for player attached object (like with Universal Tracker) higher values are recommended.

Ignore rotation can be used in cases where you want to have the object look at a particular spot or generally not rotate with the Source object. Thins like Rotation / LookAt or Aim constraints come to mind as good combinations.

Triggers / Actions

Universal Action

The bread and butter of any world reactivity, allows you to perform various actions in response to an incoming Trigger event. Think about it as a VRC SDK2 Triggers Lite

Parameters

  • Active: Determines if the behaviour is running, since toggling game objects on and off only means they won't run Update
  • Fire After Delay: Object must be enabled at all times for this to work. Specifies whether the triggers should be fired after a delay
  • Delay Length: Only visible when Fire After Delay is checked. Sets the delay length in seconds
  • Fire Animation Triggers: Specifies whether the Animation Triggers should be executed
  • Animator Triggers List: A list of Animators and Triggers to fire, you can specify the same Animator multiple times to fire multiple triggers
  • Fire Udon Events: Specifies whethere the Udon Events should be sent
  • Networked: When checked - Udon Events will be sent to targets set in Network Targets
  • Network Target: Specifies who to send the network events to
  • Udon Events List: A list of Udon Behaviours and Events to call
  • Fire Object Toggles: Specifies whether to Enable/Disable/Toggle objects from the Game Objects List
  • Game Objects List: A list of Game Objects to Enable, Disable or Toggle
  • Fire Audio Events: Specifies whether to Play the soud clips provided in the Audio List
  • Audio List: A list of Audio Sources and Audio Clips to play through them

Make sure to only use Networked option when executing this trigger locally, e.g. via a UI Button, otherwise you might cause oversync

Events

  • Trigger: Triggers this Universal Action
  • Activate: Activates the behaviour so it will react to Trigger events
  • Deactivate: Deactivates the behaviour so it will no longer react
  • Toggle: Toggles the active state, provided for convinience

Usage / Examples

Universal Action will probably be the most used behaviour in your world, as its basically a simplified trigger from SDK2. It is not as deep as the original triggers, though, so you are expected to combine it with more specific behaviours from Udon Toolkit or other places to extend its functionality.

This component makes it pretty trivial to do things via UI Buttons simply by calling a SendCustomEvent on it with Trigger as the event name.

An example of setting up a mirror toggle via UI Button would look like this:

  • Add a VRC Mirror prefab, disable it to save performance by default
  • Add a Universal Action Controller to the Mirror object
  • Make sure Active is checked, check Fire Object Toggles, click on the Game Objects List and click Add Element
  • Drag your Mirror object into the empty field, select Toggle in the dropdown on the right
  • Add a UI -> Button to your scene, set the Render Mode to World Space and scale it way down and place it where you want
  • Add a Ui Shape component to the Canvas
  • Change canvas layer to Default
  • Click on your Button inside the Canvas and add a new On Click() event by clicking the small + icon in the bottom right
  • Drag and Drop your Mirror object into the empty field that appeared
  • In the dropdown next to Runtime Only select UdonBehaviour -> SendCustomEvent (its all the way at the bottom)
  • Type Trigger in the text field

You're done! Now you can toggle your mirror via UI button in Udon.

The major thing to note here is to make sure that the component and the game object its on is always enabled if you're using the Delay parameter, otherwise it will never fire as the Update method will never be called.


Secret Actions

Sends events to udon behaviours based on the player's name

Parameters

  • Active: Determines if the actions will be executed on Start
  • Actions List: A list of Udon Behaviours and Events to send to them

Events

  • Trigger: Executes the logic again, you will probably want this to be called from the network to run for everyone again

Usage / Examples

Ever wanted to have something special activate only for particular users? This behaviour does exactly that! Combine this with Universal Action to do something special for that user, or specify behaviours of your own.

If sending events once isn't enough - you can use the Trigger event to fire it again.


Networked Trigger

A "proxy" of sorts that expects a "Trigger" event and sends Networked events to specified behaviours

Parameters

  • Event Target: Specifies who to send the events to
  • Udon Events List: A list of Udon Behaviours and events to send to them

Methods

  • Trigger: Fires the events on the provided behaviour over the network

Usage / Examples

Think about this as a very slimmed down Universal Action that can only send events to other Udon Behaviours. While its not that useful on its own - it might serve as a nice layer between UI Buttons and some other behaviours that you want to call for everyone in the room, or their owners.

You can achieve the same things by using Universal Action and checking the Networked checkbox, but it is heavier as is, so this separation is just a way to simplify things.


Area Trigger

Sends events to other behaviours when an object enters and exits a trigger collider

Parameters

  • Active: Specifies whether the triggers will fire, as just disabling the object doesn't stop it from reacting to enter/exit events
  • Collide With: Specifies the list of layers to filter out the objects you don't want to react to
  • Networked: Specifies wether the events should be sent over the network or only fired locally
  • Network Target: Specifies who to send the network events to
  • Enter Events List: A list of Udon Behaviours and Events to send when the correct object enters the trigger collider
  • Exit Events List: A list of Udon Behaviours and Events to send when the correct object exits the trigger collider

Events

  • Activate: Activates the behaviour so it will react to objects
  • Deactivate: Deactivates the behaviour so it will no longer react
  • Toggle: Toggles the active state, provided for convinience

Usage / Examples

This is an equivalent of VRC SDK2's Trigger Enter and Trigger Exit triggers with some small exceptions due to current Udon limitations (as of July 2020).

The UI will try to guide you around the main pitfalls, but in short - you should follow this small set of rules to have everything working as expected.

  • Setting Collide With to either Player or PlayerLocal on one of the default layers - won't work, as vrchat doesn't allow us to check whether the player is local or remote. One of the solutions to this is to create a new layer in unity, make it collide with either of these and set the Area Trigger to it
  • Generally speaking you would want the Area Trigger to be on the MirrorReflection layer to avoid some weird vrchat issues, unless you have a case where you need a custom layer, e.g. like the one described above
  • Do not use the Networked option if Collide With is set to Player, as this will make everyone send events to everyone all the time, causing oversync and possibly desyncing people in the instance. A good rule of thumb when it comes to things like this goes like: "if everyone can see object X enter trigger Y - you can keep everything local"

Interact Trigger

Makes something react to player interaction, VRC SDK2-style

Parameters

  • Active: Specifies whether the object from being interactible
  • Interaction Text: Sets the text shown when hovering over the object
  • Proximity: Sets the interaction distance of the object
  • Networked: Specifies whehter the Udon Events should be sent to other players
  • Network Target: Specifies who to send the Udon Events to
  • Udon Events: A list of Udon Behaviours and Events to send

Methods

  • Interact: Sends events to provided Udon Behaviours
  • Activate: Activates the behaviour so the object will become interactable
  • Deactivate: Deactivates the behaviour so the object will no longer be interactable
  • Toggle: Toggles the active state, provided for convinience

Usage / Examples

This is an almost one to one equivalent of the VRC SDK2 Interact trigger. Use in combination with Universal Action to do something when user clicks on an object.

Activate/Deactivate/Toggle events will also allow you to disable the highlight on the object, if you don't want it to be interactable anymore.


Object Boundary Trigger

Sends Events to Udon Behaviours if a target object crosses a particular threshold and disables itself (by default

Parameters

  • Active: Toggles the threshold checks on and off
  • Target: The target object to observe
  • Cross Mode: Makes this trigger run every time the Target crosses the threshold (either way), also makes it so the trigger doesnt disable itself after the threshold is crossed
  • Test Mode: Specifies whether the trigger will fire if ALL or ANY of the specifies boundaries are crossed
  • Boundary List: A list of conditions and coordinates to check against, e.g. Above Y: 10 will make the trigger fire events if the Target gets above 10 units on Y coordinate
  • Networked: Specifies whehter the Udon Events should be sent to other players
  • Network Target: Specifies who to send the Udon Events to
  • Udon Events: A list of Udon Behaviours and Events to send

Events

  • Trigger: Fires the events specified in the Udon Events list
  • Activate: Activates the behaviour so it will start checking the boundaries
  • Deactivate: Deactivates the behaviour so it will no perform any checks
  • Toggle: Toggles the active state, provided for convinience

Visuals

Skybox Adjustment

Switches skybox materials or smoothly adjusts values of a single skybox material

Parameters

  • Default Skybox: First skybox material to transition from
  • Default Floats List: A list of numeric parameters to transition from
  • Default Color List: A list of color parameters to transition from
  • Default Vector3 List: A list of Vector3 parameters to transition from
  • Active Skybox: _This should be set to the Default Skybox material if not using Instant Transition. Second skybox material to transition to
  • Active Floats List: A list of numeric parameters to transition to
  • Active Color List: A list of color parameters to transition to
  • Active Vector3 List: A list of Vector3 parameters to transition to
  • Instant Transition: Makes the skyboxes switch instantly
  • Lerp Time: Defines the time, in seconds, over which the Float/Color/Vector3 values will be transitioned from default values to active and vice-versa

Events

  • Trigger: Performs a transition from default to active. Send it again to transition back

Usage / Examples

Main thing to decide on when using this is wether you need to transition instantly or slowly over time. If you want to transition instantly - its very simple

  • Prepare 2 skybox materials, plug one into the Default Skybox and the other into Active Skybox
  • Send a Trigger event from one of the Udon Toolkit's many triggers when you want to switch
  • Done

If you want to slowly transition between different settings, e.g. between high exposure and low exposure to imitate the day/night cycle - its a bit of a different setup

  • Uncheck the Instant Transition checkbox and specify the Lerp Time in seconds
  • Expand the Default Floats List and click Add Element
  • Choose _Exposure from the dropdown and set the value you want to transition from (e.g. 1.3)
  • Expand the Active Floats List and click Add Element
  • Choose _Exposure from the dropdown and set the value you want to transition to (e.g. 0.2)
  • Send a Trigger event from one of the Udon Toolkit's triggers when you want to start transitioning
  • Done

As a sidenote - you can make it slowly transition back and forth with by setting Lerp Time to some high value, like 600 seconds, and creating a Universal Action trigger that will be delayed by like 605 seconds (just enough for everything to settle down). Then send Trigger Events both to the Skybox Adjustment and the Universal Action and it will make the skybox transition to the dark values over 10 minutes, and then transition back. To loop that - you can make Universal Action send Trigger event to itself too, so it will constantly call itself every 605 seconds


Fog Adjustment

Switches between two different fog settings - instantly, or over time

Parameters

  • Default Fog Color: First fog color to transition from
  • Default Fog Density: Only visible if the fog mode is not Linear. First fog density to transition from
  • Default Fog Start: Only visible if the fog mode is Linear. First fog start range to transition from
  • Default Fog End: Only visible if the fog mode is Linear. First fog end range to transition from
  • Active Fog Color: Second fog color to transition to
  • Active Fog Density: Only visible if the fog mode is not Linear. Second fog density to transition to
  • Active Fog Start: Only visible if the fog mode is Linear. Second fog start range to transition to
  • Active Fog End: Only visible if the fog mode is Linear. Second fog end range to transition to
  • Fog Fade Time: Specifies the duration of the transition, 0 to make it instant
  • Start Active: Makes it so the fog will start from the active state, so the first transition will be Active to Default, instead of the other way around
  • Set Initial State: Applies the Default or Active fog settings, based on whether the Start Active checkbox is set

Events

  • Activate Fog: Explicitly transitions from Default to Active state
  • Deactivate Fog: Explicitly transitions from Active to Default state
  • Trigger: Switches between the two states or starts a smooth transition

Usage / Examples

Very similar to Skybox Adjustment in terms of functionality.
Set the Default and Active setting and then use something like an Area Trigger to switch between them when a player enters or exits a particular area.

Clone this wiki locally