Geographic data in an AR world

Hey all, Student looking for a hand here!

Im trying to render geographical data in an AR App using unity and ARCore. My complication is that i can’t get the AR world to be aligned with real life north, here’s what i’m currently trying:

I have set my XRorigin as a public property, and set it through the editor, i then set it’s rotation to point towards north, or atleast what the device believes to be north. This seems to work and i have verified with debug statements, it gets a rotation.
public XROrigin arSessionOrigin;
public void SetARNorth()
{
arSessionOrigin.transform.rotation = Quaternion.Euler(0f, -trueHeading, 0f);
}

i then spawn a prefab as such, with toPlace being a property set through the editor as with the XRorigin
GameObject SpawnObjectAtUTMCoordinates(GameObject toPlace, Vector3 startCoords, Vector3 stopCoords, UnityEngine.Color color)
{
startCoords = ToUnityCoords(startCoords);
stopCoords = ToUnityCoords(stopCoords);

Vector3 direction = stopCoords - startCoords;
float distance = direction.magnitude;
direction.Normalize();

Quaternion rotation = Quaternion.LookRotation(direction);

//var pipe = Instantiate(toPlace, arSessionOrigin.transform, false); attempted this aswell, didn’t seem to work

var pipe = Instantiate(toPlace, startCoords - offset, Quaternion.identity);
pipe.transform.localRotation = rotation;

pipe.transform.localScale = new Vector3(toPlace.transform.localScale.x * 2, toPlace.transform.localScale.y * 2, distance);

//Set the color of the prefab
pipe.GetComponent().material.color = color;

return pipe;

}
If anyone could give me a hand that would be much appreciated!

If this is working, then what is your question?

I’m sorry my wording was bad, i have verified that the XROrigin GameObject gets a rotation, but all the objects i have spawned around it do not seem to get rotated along with it. This is the case if they’re spawned as children of the object or not. Aswell as if the rotation is applied before or after the objects are spawned. Hope that makes more sense.

When you modify the Transform of a GameObject, all of its children are also modified. There is nothing special about XROrigin GameObjects in this way. You can verify this in the Editor with XR Simulation enabled. Testing in the Editor is a nice way to look at your Hierarchy window while your app is running to help debug runtime behavior.


Thanks for sticking with me!

What I would like to see is here in scenario 1, where I rotate the origin 90 degrees clockwise, for the pipes in the world to rotate along in space not just in rotation as in scenario 2. I have seen it behaving like scenario 1 sometimes, but it seems like it doesn’t rotate all the way, or at least it varies wildly based on what the rotation of the origin is set to. Can you confirm if it is intended to work as scenario 1 or 2? I think that would be all from me then.

So the behavior here depends on the relationship between these GameObjects, and the pivot point of the rotation.

To achieve scenario 1, your Pipe GameObject should be a child of the XR Origin GameObject. Then when you rotate the XR Origin GameObject, all of its children will rotate with it. This can give unexpected results if the pivot point of the rotation is not the XR Origin Transform’s position, which is the only thing I can imagine that might be giving you trouble here.