Origin shifting, problems with UI

I have an issue with my UI screen, it stops working when I move away from the center of origin. And I don’t even have to go too far for it to stop working. I followed direction in this article, and added origin shifting. Placing Objects on the Globe – Cesium.

Here it says " Automatic origin shifting can be enabled by adding the CesiumOriginShift component to the main camera."

And then it says " The camera should be parented by a game object containing a CesiumGeoreference component." Can you please explain that part, because when I parent camera to anything that has CesiumGeoreference component, it does not behave well.
The main screen that I need to work is my main way for people to explore the world, and I need it to work well no matter how far they travel. I tried adding “global anchor” to the main UI screen, but it didn’t make a difference.

Thanks, Evgeniya

ezgif.com-video-to-gif (1)

Anything with a CesiumGlobeAnchor has to be parented by a CesiumGeoreference, or else it won’t keep track of its global state. Your screenshots show that your globe-anchored objects aren’t underneath the CesiumGeoreference.

And then it says " The camera should be parented by a game object containing a CesiumGeoreference component." Can you please explain that part, because when I parent camera to anything that has CesiumGeoreference component, it does not behave well.

What part of isn’t “behaving well”?

The main bug is that the avatar is locked in place when I put it under Cesium georeference. However, it goes away when I do “build and run” a second time without changing anything. But the UI screen stops working anyway just a few meters away from the origin. I went around all of the UI elements to make sure Main camera is attached to the canvas, and that all UI elements have Mesh Rendered. Still does not work, and I get a ton of warning messages.


Okay, let’s back up. Can you describe what you want your UI to do? The components you’re using don’t seem to be helping you with that.

The main bug is that the avatar is locked in place when I put it under Cesium georeference.

Assuming the “avatar” contains a CesiumGlobeAnchor component, this is supposed to happen. A CesiumGlobeAnchor “anchors” the object to a specific location on the globe. So if you want an object to stay at a specific point (e.g., a model of a building at a certain location), you can use a CesiumGlobeAnchor to “anchor” that object to the globe. You can move the object still, but you’d have to program the movement yourself. In other words, if you just drag the CesiumGlobeAnchor onto your object and do nothing else, it’s not going to move with you when you move away.

From what I could infer from the short description, it sounds like you need the UI to follow the user when they walk away. But I can’t tell what you want that to look like. Is it supposed to literally follow the user as they walk? Or is the UI supposed to stay at the location the user activates it?

@joseph.kaile Do you think you can help me here? I run a bunch of tests, here are the issues that come up:

  1. When I place XR origin under “Cesium Georeference” I have two types of bugs that go away after I click “build and run” 2-3 times.
  • I am either locked in place and can’t move
  • Terrain is flying away.
  1. I made 3 copies of the same UI screen. The first one has no globe anchors attached, and works only within a certain perimeter. The second one has Globe anchor attached to the parent object only. As you can see the screen exhibit jittering, but still works, stops working outside of a certain perimeter. The third UI has Globe anchor elements attached to all of the children object, and they have disappeared in play mode, and the position of UI screen also changed.
    Any tips how to fix that?

Thanks, Evgeniya

Hello @VRTravelExpo,

In regard to the first problem,

I suggest adding the “CesiumOriginShift” script to the XR origin GameObject. When you attach this script, it also automatically attaches a Cesium Globe Anchor script as well.

For reference, I also set up a scene with the XR origin under a Georeference here ( Add sample scene for dynamic camera in VR by joseph-kaile · Pull Request #62 · CesiumGS/cesium-unity-samples (github.com)).

Thanks for sharing this, I inspected your scene, and made some adjustments in mine. Added Origin Shift to the XR Origin instead of the Main Camera. However, the UI that that is further away still does not work. They both have Globe Anchor attached to the parent object. The one which is closer works fine. I tried again attaching Globe Anchors to each child object, but all UI elements vanished, only screen mesh is left standing as seen above.

OK, first I do not think adding Globe Anhors to each child object should be necessary.

Secondly, if the UI starts flickering that seems that the UI is far from the origin.

I tested this in my scene:

I added a UI Canvas and placed it far away from the origin. I also added a Globe Anchor to the root object (Canvas):

Its position relative to the camera is:
(-11911.94, -227.1545, 34104.79).
I wouldn’t expect this to work with these coordinates.

When I zoom up to the canvas, the position shrinks to something smaller:

Could you verify that the canvas transform values get to these relatively small values?

My Main_Screen transform values are very small. The one which stops working is only 74 meters away from the origin. Also, not sure if that matters, but my UI is very complex, the parent is a mesh and all of the elements, including the canvas and UI buttons are nested. They all have different original transform values, which were adjusted to fit the current UI. I can try finding root Canvas objects, but I have several of them under one UI screen.

This screenshot does not show Globe Anchor attached, because I was experimenting placing it to child objects, but I did try all ways.

Im trying to recreate the same UI setup.

I have a gameobject with a Globeanchor attached to it. I also have 4 Canvas’ with 4 different types of UI elements attached. It worked as expected.

Maybe this will work:

Putting the MiddleScreen_03 gameobject underneath a blank GameObject. And then attaching a globe anchor to that blank GameObject.

Do you also see this problem using the XR device simulator?

No, I am only testing in the headset. Let me start from scratch, and see if I can get the basic UI working and then move my elements there separately. I’ll get back to you.

So, I tested a brand new scene and two super simple UIs - one with the parent GameObject and Canvas underneath it, and another one just the Canvas (both parents with Globe anchor). As before, the nearest button works, and the farthest don’t. Its as if the buttons don’t exist in the space at all, Ray Interactor just passes through them like there is nothing in that space. I know my users will want to venture off and explore terrains, and there will be no way for them to get out of that scene if I don’t get this working. It is probably difficult for you to test it with the device simulator, cause you have to teleport pretty far away from where you landed.

Thank you so much for your help, Evgeniya

I put a button on the opposite side of the Denver sample map and it worked. Maybe there are some settings that is making the Ray interactor not work properly?

I set the Max Raycast distance pretty far in order to teleport faster.

That value is too big, it will be hitting unwanted targets. But I was doing more tests with the device simulator, and I can confirm the behavior is exactly the same as in the headset. The button works fine once you first enter the game. And it appears there is no difference how far the buttons are located. The problem is with XR origin’s position, once it gets closer to the buttons - or farther away from where it landed, the buttons stop registering. And it appears there is no difference if XR origin is close to Georeference center point or not on start; I moved it far away from it and the behavior was still the same. I tested it in my other scenes without Cesium components, and no matter how far I go UI elements work no problem. So there is something internally that is shutting down the buttons with avatar’s travelling distance. Maybe origin anchor script does not recognize UI buttons?
ezgif.com-video-to-gif (2)

Interesting, I’m wondering if after you go a certain distance, all the buttons start working…

This is very mysterious. It seems to only be happening in your projects. Is there a way I could get a very simple Unity project that has this problem that I could reproduce on my end?

I am using XR Origin set up from this project, but I updated the project to the latest Unity 2022.3.4f1.

I can try setting up my own rig from scratch using the input system, my only concern is that this rig works fine in every other regular scene, so something is conflicting specifically with Cesium. I know a lot of developers like to start with this project because it has a lot of pre built functionality and prefabs.


I just tried setting up a quick scene using the above Project. However I couldn’t get the button to stop working. Are you using the latest version of Cesium for Unity?

Yes, was using the latest one, but I will try to re-install it.

I recall there is an issue that was made about Origin Shift and XR:

Origin Shifting and XR bug · Issue #168 · CesiumGS/cesium-unity (github.com)

It doesn’t suprise me that Bad Things happen when the Cesium Origin Shift is attached directly to the camera.

Could you confirm to me that you only have the Origin Shift script attached to the GameObject highlighted below?