How to make a spawn point in unity using XRI Toolkit for VR Game Development

Hello there, I’d like to create a VR multiplayer game using Unity version 2022.3.5, XRI Toolkit version 2.4.3, and Normcore version 2.1. I intend to develop a system where, upon entering a room, players will spawn at specific points.

I have tried the code below, but I’m facing an issue where on my device, other players have spawned at the designated spawn point. However, on other players’ devices, they still spawn at the same point as me (origin). Is there a way to resolve this matter?

Here’s the code :

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using Normal.Realtime;

public class PlayerSpawnManager : MonoBehaviour
{
public Transform spawnPoints; // Array untuk menyimpan titik spawn pemain lain
private RealtimeAvatarManager avatarManager; // Instance dari RealtimeAvatarManager

private void Start()
{
    avatarManager = GetComponent<RealtimeAvatarManager>(); 

   
    avatarManager.avatarCreated += SpawnPlayer;
}

private void SpawnPlayer(RealtimeAvatarManager avatarManager, RealtimeAvatar avatar, bool isLocalAvatar)
{
    
    Transform spawnPoint = spawnPoints[Random.Range(0, spawnPoints.Length)];

 
    RealtimeTransform realtimeTransform = avatar.GetComponent<RealtimeTransform>();

 
    realtimeTransform.RequestOwnership();
    realtimeTransform.transform.position = spawnPoint.position;
    realtimeTransform.transform.rotation = spawnPoint.rotation;
}

}

I am still very new and not familiar with this, so I need your help!

Great question! You’re on the right track, but RealtimeAvatarManager is probably fighting you here.

So RealtimeAvatarManager instantiates your RealtimeAvatar prefab, and it sets the root transform to match the transform that’s programmed into the Root slot on the RealtimeAvatarManager in the Unity Editor. If you then try to manually override the RealtimeAvatar’s root Transform position like you’re doing here, RealtimeAvatarManager will set it back the next frame.

What you want to do here is create an empty game object in your scene to represent the local player’s Root if you don’t have one already. Then wire it into that Root slot on RealtimeAvatarManager. Once that’s set up, you can position that transform at the spawn point of your choice with a component like this:

class PlayerRootSpawnPoint {
    private void Awake() {
        // Grab a random spawn point
        Transform spawnPoint = spawnPoints[Random.Range(0, spawnPoints.Length)];

        // Place this game object at that spawn point
        transform.position = spawnPoint.position;
        transform.rotation = spawnPoint.rotation;
    }
}

Let me know how this works!

Max

Thank you for the reply!

I actually have this solved yesterday. But Thank you again for replying!

how you solve this problem?
i have the same question too