Origin shifting, problems with UI

Hi @VRTravelExpo,

I noticed that the XR Interaction Toolkit may have an issue with the UI Document from the Unity UI Toolkit. It seems that there may be a bug causing this problem. I’ve found a workaround that might help you. I wrote a simple script that iterates through all the raycasters in the scene and disables any Panel Raycaster scripts attached to them. This is just a workaround, and futher investigation may be needed to determine if this is the actual problem. I hope this helps!

using UnityEngine;
using CesiumForUnity;
using UnityEngine.XR.Interaction.Toolkit;
using UnityEngine.EventSystems;
using UnityEngine.UIElements;

public class AttachTeleportArea : MonoBehaviour
{
    void Start()
    {
        var modules = RaycasterManager.GetRaycasters();
        for (int i = 0; i < modules.Count; ++i)
        {
            var module = modules[i];
            var panelRaycaster = module.gameObject.GetComponent<PanelRaycaster>();
            if(panelRaycaster != null)
            {
                panelRaycaster.enabled = false;
            }
        }
        int teleportLayer = InteractionLayerMask.GetMask(new string[] { "Teleport" });
        Cesium3DTileset tileset = GetComponent<Cesium3DTileset>();
        if (tileset != null)
        {
            tileset.OnTileGameObjectCreated += go =>
            {
                var ta = go.AddComponent<TeleportationArea>();
                ta.interactionLayers = teleportLayer;
            };
        }
    }
}
1 Like

Great, this worked! Thank you! Please, let me know if something needs to be updated once you find the actual problem. I appreciate your help.

Evgeniya

Just noticed the problem is back. It appeared to work when I first tested it with this new script, but as I continued to build the app it is back again…

I’m sorry the error is back. I’m not sure how to reproduce the error. Is it still being triggered the same way, i.e. moving too far from the origin? i.e. does it only happen after interacting with UI elements?

When the error appears, could you check if the Panel Raycaster is indeed disabled? In Play Mode, look for the GameObject with the name “EventSystem”, and underneath that look for the GameObject named “CesiumCreditSystemUIPanelSettings” and check that the PanelRaycaster script is indeed disabled.

The script disables this object on Start but maybe there is some other script that reactivates it? Maybe going further by disabling the GameObject would finally fix the issue? i.e.

        {
            var module = modules[i];
            var panelRaycaster = module.gameObject.GetComponent<PanelRaycaster>();
            if (panelRaycaster != null)
            {
                panelRaycaster.enabled = false;
                module.gameObject.SetActive(false);
            }
        }

Another question is whether the error is the same error or not. I’ve encountered another error using the VRCore template and I made an issue here: Cesium 3D tileset causes UI shutdown in VR Core template · Issue #359 · CesiumGS/cesium-unity · GitHub

No, the PanelRaycaster is not being disabled on Play.


I added suggested line, but same result.

module.gameObject.SetActive(false);

It appeared to work earlier, when I made a fresh copy of my project. But maybe something is being overridden when I do “built and run.”

And no, I don’t have to interact with UI, I can just move away from the origin point for this to happen.

OK, I was able to reproduce the error in a different scene.

So, using the brute force approach of disabling all Panel Raycasters, this code worked for me:

        PanelRaycaster[] panelRaycasters = Object.FindObjectsOfType<PanelRaycaster>();
        foreach (var panelRaycaster in panelRaycasters)
        {
            panelRaycaster.enabled = false;
        }

Thank you, can you please confirm is this is how the new script should look like now?

using UnityEngine;
using CesiumForUnity;
using UnityEngine.XR.Interaction.Toolkit;
using UnityEngine.EventSystems;
using UnityEngine.UIElements;

public class AttachTeleportArea : MonoBehaviour
{
void Start()
{
// Disable all panel raycasters in the scene
PanelRaycaster panelRaycasters = Object.FindObjectsOfType();
foreach (var panelRaycaster in panelRaycasters)
{
panelRaycaster.enabled = false;
panelRaycaster.gameObject.SetActive(false);
}

    int teleportLayer = InteractionLayerMask.GetMask(new string[] { "Teleport" });
    Cesium3DTileset tileset = GetComponent<Cesium3DTileset>();
    if (tileset != null)
    {
        tileset.OnTileGameObjectCreated += go =>
        {
            var ta = go.AddComponent<TeleportationArea>();
            ta.interactionLayers = teleportLayer;
        };
    }
}

}

Yep. That looks good to me.

Ok, it works so far. Will do more builds and tests tomorrow. Thank you!

I was doing more tests, and the script above worked only once. However, I was able to modify it and found a more aggressive workaround using coroutine. I tested it across multiple scenes and it works so far.

using System.Collections;
using UnityEngine;
using CesiumForUnity;
using UnityEngine.XR.Interaction.Toolkit;
using UnityEngine.EventSystems;
using UnityEngine.UIElements;

public class AttachTeleportArea : MonoBehaviour
{
private bool keepChecking = true;

void Start()
{
    // Start the coroutine to keep monitoring PanelRaycasters
    StartCoroutine(ContinuouslyCheckAndDisableRaycasters());

    int teleportLayer = InteractionLayerMask.GetMask(new string[] { "Teleport" });
    Cesium3DTileset tileset = GetComponent<Cesium3DTileset>();
    if (tileset != null)
    {
        tileset.OnTileGameObjectCreated += go =>
        {
            var ta = go.AddComponent<TeleportationArea>();
            ta.interactionLayers = teleportLayer;
        };
    }
}

IEnumerator ContinuouslyCheckAndDisableRaycasters()
{
    while (keepChecking)
    {
        PanelRaycaster[] panelRaycasters = Object.FindObjectsOfType<PanelRaycaster>();
        foreach (var panelRaycaster in panelRaycasters)
        {
            if(panelRaycaster.enabled)
            {
                panelRaycaster.enabled = false;
            }
        }
        yield return new WaitForSeconds(0.5f); // Check every half second
    }
}

private void OnDestroy()
{
    keepChecking = false;
}

}

1 Like

Does this script work? I keep having the same problem. Seems to have no effect on the operation of the program has been ignored
@joseph.kaile @janine
I also have this problem, you must have met there, how to solve it?