Unity-Technologies / arfoundation-samples

Example content for Unity projects based on AR Foundation
Other
3.07k stars 1.15k forks source link

ARCollaborationData: ARParticipant and sessionid #355

Closed pestantium closed 4 years ago

pestantium commented 5 years ago

From this presentation (https://developer.apple.com/videos/play/wwdc2019/610/), I realized that the session ID on one phone must match the ARParticipant.sessionid. In the log I do not see that they are equal.

My arsid:55d375c2-d614-b16d-3d8a-2caaeb29924e ARParticipant:fa86a339-2116-12d1-c65c-7905e9de2eed User:iPhone XS session id:9bea20f8-eefd-9b43-99db-eb547a02fa9e User:iPhone7 session id:55d375c2-d614-b16d-3d8a-2caaeb29924e

Sometimes even local identifiers are not equal

My AR SessionID:5b6adbc0-1876-82c9-3f24-95a489e7367d ARParticipant SessionID:908359ac-32f7-efea-53a6-7c6f08cd1510 User:iPhone XS session id:34863b6a-8d7a-5c42-bfe6-f8a467f3e891 User:iPhone7 session id:0679d009-1ca1-5f8c-f62f-86f95ee373a0

Code `public class ARIDTest : MonoBehaviour { [SerializeField] private ARParticipantManager m_arpm;

private void OnEnable()
{
    m_arpm.participantsChanged += PartipantsChangeCallback;    
}

private void OnDisable()
{
    m_arpm.participantsChanged -= PartipantsChangeCallback;
}

private void PartipantsChangeCallback(ARParticipantsChangedEventArgs args)
{
    if (args.added.Count > 0)
    {
        string log = "My arsid:" + FindObjectOfType<ARSession>().subsystem.sessionId.ToString() + '\n';
        foreach (ARParticipant arp in args.added)
        {
            log += "ARParticipant:"+arp.sessionId.ToString();
        }
        HoloKitUser[] users = HoloKitCollaboration.Instance.users.GetPlayers();
        foreach (HoloKitUser user in users)
        {
            log += "User:" + user.username + " session id:" + user.arsessionid;
        }
        Debug.Log(log);
    }
}

}`

from user: CmdARSessionID(FindObjectOfType<ARSession>().subsystem.sessionId.ToString());

In the application, I use the synchronization from the example (ARCollaborationData/Mutipeer), and UNET for logic. How can I tie the positions of players to the respective ARParticipant?

tdmowrer commented 5 years ago

What would you expect to be equal in your example?

A participant's sessionId is the identifier of the session from which it came, so it should be different from "My arsid".

pestantium commented 5 years ago

In first log My arsid = User:iPhone7 session id (local device) but ARParticipant != User:iPhone XS session id (Participant device)

tdmowrer commented 5 years ago

Sorry, but it still isn't clear to me what you are expecting to happen. You've provided the output produced by the code snippet, which appears reasonable to me.

This is the information provided by ARFoundation:

My arsid:55d375c2-d614-b16d-3d8a-2caaeb29924e
ARParticipant:fa86a339-2116-12d1-c65c-7905e9de2eed

Which is what I would expect. HoloKitCollaboration is not part of ARFoundation and I do not know how it generates its identifiers.

pestantium commented 5 years ago

You can use this code for testing without dependencies:

`using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.XR.ARFoundation; using UnityEngine.UI;

public class ARIDTest : MonoBehaviour { [SerializeField] private Text m_text;

private ARParticipantManager m_arpm;
private ARSession m_arsession;

private void Awake()
{
    m_arpm = FindObjectOfType<ARParticipantManager>();
    m_arsession = FindObjectOfType<ARSession>();
}

private void Start()
{
    string log = string.Format("My AR Session ID:{0}{1}", m_arsession.subsystem.sessionId.ToString(), System.Environment.NewLine);
    LogData(log);
}

private void OnEnable()
{
    m_arpm.participantsChanged += PartipantsChangeCallback;    
}

private void OnDisable()
{
    m_arpm.participantsChanged -= PartipantsChangeCallback;
}

private void PartipantsChangeCallback(ARParticipantsChangedEventArgs args)
{
    if (args.added.Count > 0)
    {
        string log = string.Format("My AR Session ID:{0}{1}", m_arsession.subsystem.sessionId.ToString(), System.Environment.NewLine);
        foreach (ARParticipant arp in args.added)
        {
            log += string.Format("ARParticipant:{0}{1}", arp.sessionId.ToString(), System.Environment.NewLine);
        }
        LogData(log);
    }
}

private void LogData(string log)
{
    m_text.text = log;
}

}`

Now I understood the previous error. The AR Session ID changes after the AR synchronization. Earlier, I compared the participant parameter with the session identifier obtained on the start, before synchronization. After syncing My AR Session ID (the parameter will be changed and will be equal) == ARParticipant on other phone.

I want to ask for advice or an example. Player one creates a gameObject (unique, for example with text) and he must follow his ARParticipant on all devices. To do this, after synchronization, I need to transfer my sessionId and bind gameObject to transform of the corresponding ARParticipant? Or is there another way to do this?

pestantium commented 5 years ago

An additional question is how do I know if synchronization has occurred on this device?

pestantium commented 4 years ago

The AR Session ID changes after the AR synchronization