-
Notifications
You must be signed in to change notification settings - Fork 5
Performance and Optimization
Portal rendering is approximately as expensive as rendering a VRC Mirror. Every frame, the portal needs to render the entire scene again (twice, for each eye in VR), which means re-rendering the world & avatars!
To maximize performance, you should make sure to only have the portal active when the local player could possibly see it. Both portals in a pair do NOT need to be active at once, unless the player could actually see both portals at once.
One way to activate the portal on demand is with a trigger collider script which turns the portal on when the local player enters it, and turns the portal off when they leave it. For example, create a new GameObject and add a trigger Box Collider to it which covers the area near the portal. Then, add an UdonBehaviour to that new GameObject with an U# script PortalEnabler.cs containing the following code:
using UdonSharp;
using UnityEngine;
using VRC.SDKBase;
using VRC.Udon;
[UdonBehaviourSyncMode(BehaviourSyncMode.None)]
public class PortalEnabler : UdonSharpBehaviour
{
public GameObject portal;
public override void OnPlayerTriggerEnter(VRCPlayerApi player)
{
if (Utilities.IsValid(player) && player.isLocal) {
portal.SetActive(true);
}
}
public override void OnPlayerTriggerExit(VRCPlayerApi player)
{
if (Utilities.IsValid(player) && player.isLocal) {
portal.SetActive(false);
}
}
}In addition to a toggle script like above, consider using the activatePartnerOnTeleport and deactivateSelfOnTeleport settings on each portal.
For example, if your world contains two rooms joined by a portal pair, you may not even need a trigger collider enabler. Simply have the portal in the room the player spawns in active by default, and the other inactive by default. Enable those two setting on both portals, and the portals will automatically activate and deactivate themselves as the player travels between the two rooms. Most worlds aren't that simple though, so a trigger collider enabler will probably still be necessary!