Hi I’m hoping to get some clarity and help for an Android App I am building where I generate an AR heatmap. I will start by saying this is likely not the best method, but I will share where I’m at in case it helps. Thanks in advance if you are able to help!
TLDR: I am trying to produce a heatmap effect where I use ARFoundation Track Image Manager to produce the tracked prefab then I would like to generate a clone and leave it at its current position with a button click event and have it store the clones in a empty Game Object called “HeatMapPointHolder” that is parented to the AR camera. My thought was that it would be a good idea to parent the clones to the ARCamera to keep them in their locations at the time the button was clicked. One of my biggest issues is, how do I instantiate a clone of a prefab that hasn’t been instantiated at start.
If you know a method that will work, Im all ears. This is where Im at currently:
I am able to properly track the image and produce the prefab, but I don’t have a clue how to access the instantiated prefab- from Tracked Image Manager that is being displayed on the image. It seems that the prefab should be called m_TrackedImagePrefab so I applied a script to the session origin (called Marker Manager) to try and invoke a clone function from a script (I called CloneSphere) but its not working when I attempt to run a GameObject.Find(“m_TrackedImagePrefab”)
Here is my hierarchy:
Here is the inspector for the Session Origin:
Here is the button inspector:
Here is the Marker Manager script:
using UnityEngine;
using UnityEngine.XR.ARFoundation;
using UnityEngine.UI;
using UnityEngine.Events;
public class MarkerManager : MonoBehaviour
{
public ARTrackedImageManager m_TrackedImageManager;
public Text txt;
public UnityEvent order;
private void OnEnable()
{
m_TrackedImageManager.trackedImagesChanged += OnTrackedImagesChanged;
}
private void OnDisable()
{
m_TrackedImageManager.trackedImagesChanged -= OnTrackedImagesChanged;
}
void OnTrackedImagesChanged(ARTrackedImagesChangedEventArgs eventArgs)
{
foreach (var trackedImage in eventArgs.added)
order.Invoke();
}
}
Here is the script called CloneSphere:
using Unity.Collections;
using UnityEngine;
using UnityEngine.XR.ARFoundation;
using UnityEngine.XR.ARSubsystems;
public class CloneSphere : MonoBehaviour
{
public GameObject heatMapSphere;
public GameObject heatMapSphereClone;
public Transform heatMapPointHolder;
// Start is called before the first frame update
private void Update()
{
}
public void CloneHeatMapSphere()
{
heatMapSphere = GameObject.Find("m_TrackedImagePrefab");
heatMapSphereClone = Instantiate(heatMapSphere, heatMapPointHolder) as GameObject;
heatMapSphereClone.transform.parent = heatMapPointHolder;
}
}
My button calls (On Click Event): MarkerManager.enabled