Rex G
Rex G3d ago

Spawning

I need the realtime avatar manager to spawn the players at specific points. The players are spawning in different places each time.
3 Replies
kapa.ai
kapa.ai3d ago
Hi @Rex G. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave: ---------------------- To control where players spawn when using the RealtimeAvatarManager in Normcore, you need to set the position of the avatar prefab after it is instantiated. By default, the RealtimeAvatarManager will instantiate the avatar prefab at the origin or wherever the prefab’s transform is set, which can lead to inconsistent spawn locations. The knowledge sources do not provide a built-in way to specify spawn points directly through the RealtimeAvatarManager. However, you can subscribe to the avatarCreated event and set the position of the local avatar after it is created. Here’s how you can do it:
using UnityEngine;
using Normal.Realtime;

public class CustomAvatarSpawner : MonoBehaviour {
public Transform[] spawnPoints; // Assign your spawn points in the inspector
private int nextSpawnIndex = 0;

private void Awake() {
var avatarManager = GetComponent<RealtimeAvatarManager>();
avatarManager.avatarCreated += OnAvatarCreated;
}

private void OnAvatarCreated(RealtimeAvatarManager manager, RealtimeAvatar avatar, bool isLocalAvatar) {
if (isLocalAvatar && spawnPoints.Length > 0) {
// Choose a spawn point (e.g., round-robin)
Transform spawnPoint = spawnPoints[nextSpawnIndex % spawnPoints.Length];
avatar.transform.position = spawnPoint.position;
avatar.transform.rotation = spawnPoint.rotation;
nextSpawnIndex++;
}
}
}
using UnityEngine;
using Normal.Realtime;

public class CustomAvatarSpawner : MonoBehaviour {
public Transform[] spawnPoints; // Assign your spawn points in the inspector
private int nextSpawnIndex = 0;

private void Awake() {
var avatarManager = GetComponent<RealtimeAvatarManager>();
avatarManager.avatarCreated += OnAvatarCreated;
}

private void OnAvatarCreated(RealtimeAvatarManager manager, RealtimeAvatar avatar, bool isLocalAvatar) {
if (isLocalAvatar && spawnPoints.Length > 0) {
// Choose a spawn point (e.g., round-robin)
Transform spawnPoint = spawnPoints[nextSpawnIndex % spawnPoints.Length];
avatar.transform.position = spawnPoint.position;
avatar.transform.rotation = spawnPoint.rotation;
nextSpawnIndex++;
}
}
}
Attach this script to the same GameObject as your RealtimeAvatarManager and assign your spawn points in the inspector. This will ensure each local player spawns at a specific location. Note: The knowledge sources confirm that you can use the avatarCreated event to detect when an avatar is instantiated and modify its transform at that point, but they do not provide a built-in spawn point system, so this approach is based on the recommended event usage pattern for avatar management in Normcore Realtime XR Avatars Reference. If you need more advanced spawn logic (e.g., based on player ID or room state), you can expand the logic in the event handler accordingly. ---------------------- Note: you can ask me a follow up question by @ mentioning me again :speech_balloon: ----------------------
kapa.ai
kapa.ai3d ago
<@918869683929768036> Kapa.ai is still learning and improving, please let me know how I did by reacting below.
Rex G
Rex GOP2d ago
The root of the local player on the realtime avatar manager is what moves for some reason from I have it placed in the scene The Realtime Avatar Manager seems to just keeping spawning players at different points of the game world. I need everyone to spawn at the same entrance of the game world

Did you find this page helpful?