Skip to content

Calling Unity and VRChat types

You call Unity and VRChat types the same way you would in C# (for getting components, see Getting and calling components). Only members exposed to Udon can be called; a member that is not exposed is an error at compile time (Forms that don’t compile).

SyntaxDescriptionNote
source.Play()Playing a sound
source.PlayOneShot(clip, 0.7f)Layering a sound effect
animator.SetTrigger("Open")Switching an animation with a trigger
animator.SetBool("IsOpen", open)Switching an animation with a bool
body.AddForce(force, ForceMode.Impulse)Applying a force
Physics.Raycast(origin, direction, out hit, 12.5f)Checking for a hit with a ray
transform.Translate(velocity * Time.deltaTime)Moving every frame
transform.SetPositionAndRotation(position, rotation)Setting position and rotation
door.SetActive(!door.activeSelf)Showing and hiding
Instantiate(prefab)Copying a prefabSet the position and rotation after copying (you cannot pass them as arguments).
Input.GetKeyDown(KeyCode.Space)Reading a keyVR controller input is received through the input events on the Events page.
label.text = "count: " + countShowing text
particles.Emit(12)Emitting particles
pickup.Drop()Dropping a held object
SyntaxDescriptionErrorReasonAlternative
gameObject.AddComponent<Rigidbody>()Adding a component at run timeCS1061runtimePlace an object that already has the component and show it with SetActive
target.SendMessage("Open")Calling a method by name through Unity’s messagingCS1061runtimeCall it with SendCustomEvent
Resources.Load("Door")Loading an asset by nameCS0103runtimePass a reference in the Inspector
Instantiate(prefab, position, rotation)Copying with the position and rotation as argumentsCS1501runtimeCall SetPositionAndRotation after Instantiate(prefab)

Pass an AudioSource reference in the Inspector and call Play.

using UnityEngine;
using Tsukimi;
public class UnityTypesAudioPlay : TsukimiBehaviour
{
public AudioSource source;
public override void Interact()
{
source.Play();
}
}

Pass a clip and a volume scale to PlayOneShot.

using UnityEngine;
using Tsukimi;
public class UnityTypesAudioOneShot : TsukimiBehaviour
{
public AudioSource source;
public AudioClip clip;
public override void Interact()
{
source.PlayOneShot(clip, 0.7f);
}
}

Name the Animator parameter.

using UnityEngine;
using Tsukimi;
public class UnityTypesAnimatorTrigger : TsukimiBehaviour
{
public Animator animator;
public override void Interact()
{
animator.SetTrigger("Open");
}
}

Change a bool parameter with SetBool.

using UnityEngine;
using Tsukimi;
public class UnityTypesAnimatorBool : TsukimiBehaviour
{
public Animator animator;
private bool open;
public override void Interact()
{
open = !open;
animator.SetBool("IsOpen", open);
}
}

Call it on a Rigidbody reference.

using UnityEngine;
using Tsukimi;
public class UnityTypesRigidbodyForce : TsukimiBehaviour
{
public Rigidbody body;
public Vector3 force = new Vector3(0f, 4.5f, 1.25f);
public override void Interact()
{
body.AddForce(force, ForceMode.Impulse);
}
}

Arguments received with out are written the same way as in C#.

using UnityEngine;
using Tsukimi;
public class UnityTypesPhysicsRaycast : TsukimiBehaviour
{
public Transform marker;
void Update()
{
RaycastHit hit;
if (Physics.Raycast(transform.position, transform.forward, out hit, 12.5f))
{
marker.position = hit.point;
}
}
}

Your own Transform is available as transform.

using UnityEngine;
using Tsukimi;
public class UnityTypesTransformMove : TsukimiBehaviour
{
public Vector3 velocity = new Vector3(0f, 0f, 1.5f);
void Update()
{
transform.Translate(velocity * Time.deltaTime);
}
}

Build a rotation from angles with Quaternion.Euler.

using UnityEngine;
using Tsukimi;
public class UnityTypesTransformPlace : TsukimiBehaviour
{
void Start()
{
transform.SetPositionAndRotation(new Vector3(2f, 0.5f, -3f), Quaternion.Euler(0f, 90f, -15f));
}
}

Call it on a GameObject reference.

using UnityEngine;
using Tsukimi;
public class UnityTypesGameObjectActive : TsukimiBehaviour
{
public GameObject door;
public override void Interact()
{
door.SetActive(!door.activeSelf);
}
}

Instantiate can only be written with a single prefab GameObject as its argument.

using UnityEngine;
using Tsukimi;
public class UnityTypesInstantiate : TsukimiBehaviour
{
public GameObject prefab;
public override void Interact()
{
GameObject copy = Instantiate(prefab);
copy.transform.SetPositionAndRotation(new Vector3(1.5f, 0f, -2f), Quaternion.Euler(0f, 45f, 0f));
}
}

Read keyboard input with Input.

using UnityEngine;
using Tsukimi;
public class UnityTypesInputKey : TsukimiBehaviour
{
public GameObject door;
void Update()
{
if (Input.GetKeyDown(KeyCode.Space))
{
door.SetActive(!door.activeSelf);
}
}
}

Assign a string to the text of a TextMeshProUGUI.

using UnityEngine;
using Tsukimi;
using TMPro;
public class UnityTypesTextSet : TsukimiBehaviour
{
public TextMeshProUGUI label;
private int count;
public override void Interact()
{
count++;
label.text = "count: " + count;
}
}

Call it on a ParticleSystem reference.

using UnityEngine;
using Tsukimi;
public class UnityTypesParticlesEmit : TsukimiBehaviour
{
public ParticleSystem particles;
public override void Interact()
{
particles.Emit(12);
}
}

VRChat components are called the same way.

using UnityEngine;
using Tsukimi;
using VRC.SDK3.Components;
public class UnityTypesPickupDrop : TsukimiBehaviour
{
public VRCPickup pickup;
public override void Interact()
{
pickup.Drop();
}
}