xulipaX
Normal17mo ago
xulipa

Changing scene room duplicates XR Origin

When I change room and scene it seems to keep my XR Origin Rig, so everytime I change room/scene it creates a new one. I have seen some people just remove their XR origin rigs of the scene they are going to. However I have different Rigs for each scene, so I need to leave the XR rigs in the scene. So I'm thinking I need to destroy some before I connect to a new room?
Here is my code:

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using Normal.Realtime;
using UnityEngine.SceneManagement;
using UnityEngine.XR.Interaction.Toolkit;

public class NormalSceneLoader : MonoBehaviour
{
[SerializeField] private Realtime realtime;
[SerializeField] private string roomName;
[SerializeField] private int sceneIndex;

private XRGrabInteractable grabInteractable;

private bool isLoading;

void Start()
{
grabInteractable = GetComponent<XRGrabInteractable>();
grabInteractable.selectEntered.AddListener(OnSelectEntered);
}
void OnSelectEntered(SelectEnterEventArgs args)
{
LoadScene();
}

public void LoadScene()
{
if (isLoading) return;
isLoading = true;
realtime.Disconnect();
realtime = null;

SceneManager.LoadScene(sceneIndex);

realtime = FindObjectOfType<Realtime>();
realtime.Connect(roomName);

isLoading = false;
}
}
Was this page helpful?