ARDK Document "How to Use Shared AR_2

  • Issue category: Shared AR / Multiplayer / ARDK Documentation / Networking / VPS
  • Device type & OS version: Android / iOS
  • Host machine & OS version: Mac / Windows / Linux / Other Ex. Mac on Big Sur x.x
  • Issue Environment :
  • Xcode version:
  • ARDK version: ARDK 3.0
  • Unity version: 2022.3.17f1

I got stuck doing the [Joining a Room using SharedSpaceManager] step after going through the method you told me. Please help. I’ll tell you what I’ve done so far after the method you told me.

1. Instantiate a copy of the SharedSpaceManager.

    1. Adding SharedSpaceManager Components:
    • Added the SharedSpaceManager component to XR Origin.
    1. Refer to SharedSpace Manager in Script:
    • Make the script MySharedSpaceController the name of the script that you want to implement the shared AR-related features. Declare a reference to ‘SharedSpaceManager’ in this script and link it in the Unity Editor.

[SerializeField]
private SharedSpaceManager _sharedSpaceManager;

2. Prepare and participate in a shared AR session to the selected location

The code for preparing and participating in a shared AR session using the ‘Default Anchor’ in the location selected by the user is as follows:

private void OnLocationSelected(string defaultPayloadToSet)
{
// Create VPS Tracking Options
var vpsTrackingOptions = ISharedSpaceTrackingOptions.CreateVpsTrackingOptions(defaultPayloadToSet);

// Create Room Options
var roomOptions = ISharedSpaceRoomOptions.CreateVpsRoomOptions(
vpsTrackingOptions,
“optionalPrefixForRoom_”,
10, // Maximum number of participants
“Room Description Here!”); // Room Description

// start Shared AR session
_sharedSpaceManager.StartSharedSpace(vpsTrackingOptions, roomOptions);
}

This code is an example of the ‘OnLocationSelected’ method, which should be called when selecting a location in Dropdown. Use the ‘DefaultAnchor’ at the selected location to set up the VPS tracking and room options and forward them to the ‘StartSharedSpace’ method in the ‘SharedSpace Manager’ to initiate a shared AR session.

3. Update event listener settings and participation status UI

Set up a status-changing event listener for ‘SharedSpaceManager’ and provide users with a UI to participate as hosts or clients based on their tracking status:

[SerializeField]
private Button _joinAsHostButton;
[SerializeField]
private Button _joinAsClientButton;

protected void Start()
{
_sharedSpaceManager.sharedSpaceManagerStateChanged += OnColocalizationTrackingStateChanged;
}

private void OnColocalizationTrackingStateChanged(SharedSpaceManager.SharedSpaceManagerStateChangeEventArgs args)
{
if (args.Tracking)
{
_joinAsHostButton.gameObject.SetActive(true);
_joinAsClientButton.gameObject.SetActive(true);
}
}

4. Join as a host or client

Add a listener to the button so that the user can participate as a host or client:

protected void Start()
{
_joinAsHostButton.onClick.AddListener(OnJoinAsHostClicked);
_joinAsClientButton.onClick.AddListener(OnJoinAsClientClicked);
}

private void OnJoinAsHostClicked()
{
NetworkManager.Singleton.StartHost();
HideButtons();
}

private void OnJoinAsClientClicked()
{
NetworkManager.Singleton.StartClient();
HideButtons();
}

private void HideButtons()
{
_joinAsHostButton.gameObject.SetActive(false);
_joinAsClientButton.gameObject.SetActive(false);
}

This process makes it easy for users to participate as hosts or clients in shared AR sessions. Once all the necessary setup and preparation are complete, users can start the shared AR experience.

I wonder what action works when I build and run after completing the “Joining a Room using Shared Space Manager” step. I also wonder if I can check two players entering the room together.

Hello! What happens when you join as a host and a client? Can you send a video of you running your build?