Origin shifting, problems with UI

I just found out what the problem is, and it is nothing we discussed above. The problem is in the teleportation area script. When I started moving my assets, I run into the same problem, so I deleted everything and started moving everything one by one. The UI was working perfectly no matter how far I went, and when I brough it the teleportation script, the same problem happened again when I moved to a certain distance. Do you think you can fix that?

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

public class AttachTeleportationArea : MonoBehaviour
{
// You can drag-and-drop the desired tileset into this variable in the Inspector.
// But for demonstration’s sake, this will assume that the script is attached to
// a game object with a Cesium3DTileset component.
public Cesium3DTileset tileset;

void Awake()
{
   
    if (tileset != null)
    {
        tileset.OnTileGameObjectCreated += go => go.AddComponent<TeleportationArea>(); 
    }
}

}

So, I’ve been using the teleportation script without issues. Except the one I use is here:
cesium-unity-samples/Assets/CesiumForUnitySamples/Scripts/CesiumSamplesTeleportationArea.cs at main · CesiumGS/cesium-unity-samples (github.com)

The difference is that it is called on Start instead of Awake, and also that it needs to be attached to the 3d tileset GameObject.

Did all that, same problem
ezgif.com-video-to-gif (3)

For now, I will put a bunch of invisible planes on top of the terrain, and remove the script entirely. Hope that can be fixed at some point.

Checked back and it appears the issue has been resolved. I got this scrips and dropped it on the tileset. UI works fine when I go far.

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

public class CesiumSamplesTeleportationArea : MonoBehaviour
{
void Start()
{
Cesium3DTileset tileset = GetComponent();
if (tileset != null)
{
tileset.OnTileGameObjectCreated += go =>
go.AddComponent();
}
}
}

Unfortunately, I was celebrating too early. The same issue persisting for me. My screen still stops working once I walk away from the origin point.

Doing more tests, added a large custom plateau on top of the Cesium terrain, and removed the teleportation script provided by Cesium. Only added “teleportation area” script that came with XR interaction toolkit. But same issue occurred. Tested it AGAIN with regular Unity terrain, and there are no problems.

Patiently waiting for this to be fixed, I have a group of 30 alpha testers testing the app currently, and I have to remind them not to do more than 25 teleportations, otherwise UI will shut down. I can’t be the only one who runs into this problem.

Can anything be done ASAP please? @patrick @Shehzan_Mohammed @Kevin_Ring

We can’t fix this (ASAP or otherwise) because we can’t reproduce it and don’t know what is causing it for you. Help us reproduce the problem by providing detailed step-by-step instructions, preferably starting with the Cesium for Unity Samples project, and we can take a look!

Yes, I’d be happy to. But I prefer to use Unity 2022.3.4lts for the step by step instructions, because that’s what I use. I also packaged the project and you can see it for yourself, with two scenes - regular Unity terrain and Cesium.

  1. Start a new project, and select VR Core as a template. (Unity 2022.3.4 lts)
  2. Go to File - Build Settings - Switch platform to Android.
  3. Edit - Project Settings - Scroll down and select XR Plugin Management and change platform to Oculus (both in Android Tab and Windows)
  4. Go to Window - Package Manager - Scroll down to XR Interaction toolkit, and import XR device simulator package under Samples tab.
  5. Install Cesium via scooped registry, as per instructions on your website.
  6. Open the sample scene provided by Unity.
  7. Drop XR device simulator into the hierarchy, so you can test it on the desktop.
  8. Test it by pressing play, you can move around and switch hands by pressing tab. The main one at this time would be to use right hand and press W to teleport.
  9. Make a copy of this scene and add Cesium in that new scene, test it again and use Tab to go to the right hand, and press W to teleport. At about 20 teleportations, you will get a thousand errors that I indicated above. And this is when UI shuts down in the game. In VR W = primary2Daxis (right hand joystick).

Here is drive with the entire project. Thanks!

Evgeniya

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?