Skip to content

Callback Script

aurycat edited this page Dec 27, 2025 · 10 revisions

Callback Events

The callbackScript field on an UdonBehaviour is an optional script to receive events when the local player or an object is teleported.

Parameters are provided by updating variables on the callback script. (For Udon Graph compatibility.) Variables are set on the callback script immediately before the event is emitted.

Although not directly parameters, the callback script can also read the destPosition, destRotation, and destVelocity fields of sourcePortal to know where the player or object will be moved to.

Not all events or variables need to exist on the callback script; the callback script can just include the events and variables it cares about.

Here is the list of events:

_PortalWillTeleportPlayer

This event is sent by a portal when the local player has walked through the portal and the portal is about to teleport the player to its partner. The player has not yet been moved when this event is sent. The event is sent with the Update timing.

Parameters:

  • sourcePortal (type PortalBehaviour): The portal which the player walked into.

_PortalWillTeleportObject

This event is sent by a portal when an object has fallen through the portal and the portal is about to teleport the object to its partner. The object has not yet been moved when this event is sent. The event is sent with the FixedUpdate timing.

Parameters:

  • sourcePortal (type PortalBehaviour): The portal which the object fell into.
  • teleportedObject (type Rigidbody): The affected Rigidbody.

_PortalWillReceivePlayer

This event is sent by a portal when the local player will be teleported to it. (Note that if a portal sends a player to a bare Transform, not another portal, this event will not be emitted because there is no portal to emit it!) This event is sent immediately after the sender portal emits _PortalWillTeleportPlayer, before the player has been moved.

Parameters:

  • sourcePortal (type PortalBehaviour): The portal which the player walked into.
  • targetPortal (type PortalBehaviour): The portal receiving the player (i.e. the portal which emits this event).

_PortalWillReceiveObject

This event is sent by a portal when an object will be teleported to it. (Note that if a portal sends an object to a bare Transform, not another portal, this event will not be emitted because there is no portal to emit it!) This event is sent immediately after the sender portal emits _PortalWillTeleportObject, before the object has been moved.

Parameters:

  • sourcePortal (type PortalBehaviour): The portal which the object fell into.
  • targetPortal (type PortalBehaviour): The portal receiving the object (i.e. the portal which emits this event).
  • teleportedObject (type Rigidbody): The affected Rigidbody.

Examples

U# example

using UdonSharp;
using UnityEngine;
using VRC.SDKBase;
using VRC.Udon;

[UdonBehaviourSyncMode(BehaviourSyncMode.None)]
public class MyPortalCallback : UdonSharpBehaviour
{
    [HideInInspector] public PortalBehaviour sourcePortal;
    [HideInInspector] public PortalBehaviour targetPortal;
    [HideInInspector] public Rigidbody teleportedObject;

    public void _PortalWillTeleportObject()
    {
        Debug.Log($"The object {teleportedObject} fell through the portal {sourcePortal} and will exit {sourcePortal.partner} with velocity {sourcePortal.destVelocity}.");
    }

    public void _PortalWillReceivePlayer()
    {
        Debug.Log($"The local player is portaling from {sourcePortal} to {targetPortal}. The player will end up at {sourcePortal.destPosition}.");
    }
}

Udon Graph Example

Equivalent functionality to the U# example above.

image

Clone this wiki locally