-
Notifications
You must be signed in to change notification settings - Fork 4
Callback Script
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:
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(typePortalBehaviour): The portal which the player walked into.
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(typePortalBehaviour): The portal which the object fell into. -
teleportedObject(typeRigidbody): The affected Rigidbody.
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(typePortalBehaviour): The portal which the player walked into. -
targetPortal(typePortalBehaviour): The portal receiving the player (i.e. the portal which emits this event).
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(typePortalBehaviour): The portal which the object fell into. -
targetPortal(typePortalBehaviour): The portal receiving the object (i.e. the portal which emits this event). -
teleportedObject(typeRigidbody): The affected Rigidbody.
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}.");
}
}Equivalent functionality to the U# example above.