Hey all. Long time reader, first time posting!
I’m trying to modify AR Foundation’s “ARPoseDriver.cs” to send the resulting AR device position/rotation to a separate game object and I can’t understand why it’s not working.
Ultimately I want to just disable position/rotation on the “AR Camera” and have it be managed by the separate object (more on that below), but for now I’m not even able to send the resulting values to a dummy Vector3 and Quaternion for testing.
I’ve declared 3 values for testing in lines 17-19:
using System;
using System.Collections;
using System.Collections.Generic;
using System.Runtime.CompilerServices;
using UnityEngine;
using UnityEngine.XR;
namespace UnityEngine.XR.ARFoundation
{
/// <summary>
/// The ARPoseDriver component applies the current Pose value of an AR device to the transform of the GameObject.
/// </summary>
[HelpURL(HelpUrls.ApiWithNamespace + nameof(ARPoseDriver) + ".html")]
public class ARPoseDriver : MonoBehaviour
{
public Transform DigitalPlayer;
public Vector3 CameraPosition;
public Quaternion CameraRotation;
===
Here’s an image of how that shows in Unity Inspector (look at the public variables now displaying under "AR Pose Driver script):
And later starting at “PerformUpdate()” (which I believe overrides the regular “Update()” I’m trying to update the position value to that dummy “CameraPosition” Vector3 I’ve got set up to at least visualize if it’s receiving values (line 15 and the 2 comments are what I added):
#endif // UNITY_UNITY_2020_1_OR_NEWER
}
void Update() => PerformUpdate();
void OnBeforeRender() => PerformUpdate();
void PerformUpdate()
{
if (!enabled)
return;
//This line also does not affect pose data
var updatedPose = GetPoseData();
//Even commenting out the below two lines have no effect on the camera tracking so line 70-74 has no effect on the camera location
if (updatedPose.position.HasValue)
{
transform.localPosition = updatedPose.position.Value;
CameraPosition = updatedPose.position.Value;
}
if (updatedPose.rotation.HasValue)
transform.localRotation = updatedPose.rotation.Value * updatedPose.rotation.Value;
}
====
The rest of the file is just what’s in AR Foundation 4.1.7.
But no matter what I try (no errors in the code) I can’t get that “CameraPosition” value to show anything other than 0,0,0 when I run the editor.
I tried a different route of “breaking” the code to see where exactly the position/rotation gets called, but even when I comment out the line “var updatePose = GetPoseData();” the camera STILL gets all of the position/rotation data from ARkit.
I can’t understand where in this “ARPoseDriver.cs” code that the actual location/rotation gets returned so I can send the values to a separate GameObject.
Anyone able to help?
For context, I’ve had this method running in Unity 2017 for the last few years without a problem, but since I want to take advantage of the newer ARkit features I’m trying to get this working now in Unity 2021.1.22.
I’m doing this all for location-based games with “QR code” tracked images on the walls, so in my Unity 2017 version rather than use “QR codes” to move the entire scene to the tracked image I had it reverse-engineered so that when a “QR code” on the floor gets seen in the physical room it’s the PLAYER that gets moved around the 3D environment (rather than the 3D environment getting moved around the player). This way their 3D position always corresponds to the world position in the actual room, which makes it easy to quickly set up the game for multiplayer by just dropping a QR code on the ground and also allows me to use NavMeshes (since the 3D room never actually moves).
Sending the iPhone’s Camera location to a separate object and having the “AR Camera” location calculated separately is the first step to making this all work, which has worked great in my Unity 2017 build.
AR Foundation has added a ton of functionality that I’ve really loved, but I can’t find a way to “break” it to send the camera position/rotation data to a separate GameObject.
PS, I’m also using the “AR Foundation Remote 2.0” plugin and it’s been a dream for AR prototyping: AR Foundation Remote 2.0 | Utilities Tools | Unity Asset Store