Hello.
I’m trying to develop a project where the app should create an anchor wherever it detects an xreal marker. I tryed using the CoastersImageTracking scene as a base and then insert some components from the MappingExample demo scene for the anchors. I managed to make it create an anchor when it detects a marker, althouh it places it in a wierd position.
I don’t understand if i’m using a wrong method or what.
Here are some screenshots for some context:
here’s where i call the method (whenever it detects the marker with index 10)
Here’s the code:
[SerializeField] private GameObject prefabOPbject;
public void SetTarget(Transform newTarget)
{
target = newTarget;
Debug.Log(“sposto target”);
AddAnchor(prefabOPbject);
}
public void AddAnchor(GameObject prefab)
{
if (m_NRWorldAnchorStore == null || target == null || prefab == null)
{
return;
}
if (m_NRWorldAnchorStore.IsCreatingNewAnchor)
{
return;
}
var anchorItem = prefab.GetComponent<AnchorItem>();
if (anchorItem == null)
{
print("anchor item non trovato");
return;
}
var go = Instantiate(prefab);
go.transform.position = target.position;
go.transform.rotation = target.rotation;
Debug.Log("target position: " + target.position + " " + target.rotation + ".\nGO position: " + go.transform.position + " " + go.transform.rotation);
string key = anchorItem.key;
NRWorldAnchor anchor = go.AddComponent<NRWorldAnchor>();
anchor.UserDefinedKey = key;
bool success = anchor.CreateAnchor();
if (success)
{
print("creo il mapping thing");
MapQualityIndicator.SetCurrentAnchor(anchor, false);
ShowMapQualityIndicator(anchor);
}
else
{
print("qualcosa è andato storto");
DestroyImmediate(go);
}
}
I don’t know if there should be another method that makes it a bit easier.
[EDIT]: I forgot to mention that it actually places the anchor in the last place it detected a yellow marker, is it just an order of code executing?