juanje89
juanje894w ago

Non-vr spectator

Hi guys, I'm trying to develop a VR application and would like to include a scene for non-vr users, but I cannot seem to manage it. My VR scene has a RealTimeAvatarManager who instantiates the VR player successfully. What I did for my other non-vr scene is to duplicate the VR scene (keeping the same name for the room), but removing all VR elements (XR Interaction Setup and the RealtimeAvatarManager). What I did is to add a SpectatorManager on the same gameobject as the Realtime one, that instantiates a different prefab (no RealtimeAvatar this time). Is this the way to do it? I tried to "simulate" the AR Spectator example in the documentation, however, I get an error in the spectator scene whenever the VR client connects (RealtimeAvatar failed to register with RealtimeAvatarManager component. Was this avatar prefab instantiated by RealtimeAvatarManager?), though I can see both players in both apps. Thanks!
6 Replies
kapa.ai
kapa.ai4w ago
Hi @juanje89. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave: ---------------------- Based on the information provided in the knowledge sources, it seems like you're on the right track. However, there are a few things you might want to check: 1. RealtimeAvatar Component: All avatar prefabs that are used with RealtimeAvatarManager need to include a RealtimeAvatar component on the root of the prefab. This component is responsible for synchronizing the head + hands positions and active states. When it's first instantiated, RealtimeAvatar is given a set of transforms to track for the root of the prefab, the head, and the hands from RealtimeAvatarManager's localPlayer field, which is set in the editor inspector. source (https://normcore.io/documentation/realtime/xr/avatars#realtimeavatar) 2. RealtimeAvatarManager: This component is responsible for instantiating an avatar prefab to represent the local player as well as keeping track of avatars that were instantiated for other players in the same room. If the component is enabled and realtime is connected to a room, an avatar prefab represented by the localAvatarPrefab property will be instantiated to represent the local client. This prefab needs to include a RealtimeAvatar component on the root in order to function correctly. source (https://normcore.io/documentation/realtime/xr/avatars#realtimeavatarmanager) 3. AR Spectator View: If you're trying to simulate the AR Spectator example, make sure you've followed all the steps correctly. This includes importing the AR Foundation and the ARKit XR Plugin (iOS) or the ARCore XR Plugin (Android), importing the AR Spectator Example unitypackage, saving a copy of the Realtime + VR Player scene for the AR Spectator app, swapping the Main Camera for one that supports AR, and connecting RealtimeAvatarManager to your camera rig. source (https://normcore.io/documentation/guides/using-ar-as-a-spectator-view#create-the-mobile-ar-app) If you're still encountering issues, it might be helpful to review the documentation or reach out to the NormalVR support for more specific guidance. ---------------------- Note: you can ask me a follow up question by @ mentioning me again :speech_balloon: ----------------------
kapa.ai
kapa.ai4w ago
<@759006240646103041> kapa.ai is still learning and improving, please let us know how it did by reacting below
Mechabit
Mechabit4w ago
the built-in realtime avatar will try to register with the realtime avatar manager in the scene, if it's not there you'll get this error. Either keep both players in the same scene or make a custom avatar manager that behaves like you want it to. I'd stick to 1 scene as it's going to get confusing to keep them both updated you can just instantiate the correct player rig at runtime
juanje89
juanje894w ago
Ok, I'll try to make it all in just one scene, spectators and VR players I tried to mix everything in one single scene, by having two Realtime objects (one for VR and one for Spectator) and activating one of them depending on the platform, however, i get the same error. One Realtime object has the RealtimeAvatarManager and the other my custom SpectatorManager.
Mechabit
Mechabit4w ago
you could make one unified avatar and then switch modes based on the user if you use the default avatar manager you'll need to keep it active in both players another option is to make your own avatar manager to make it spawn the correct avatar rather than having 2 and disabling one so option 1) keep the default avatar manager and have both player avatars rolled into one option 2) edit the default avatar manager to make it spawn one of 2 avatars option 2 is pretty easy, just copy the default avatar manager and add a 2nd player avatar prefab and disable the XR rig stuff for the spectator
juanje89
juanje894w ago
Great, that is what I'm trying to do right now. I have created a script called "AvatarRoleInitializer" that is on my avatar prefab and it seems to work great, because I managed to remove the hands depending wheter it is a spectator or not, though I'm having issues setting the position of this spectator manager, but it is perhaps because of the XR Interaction Setup This is the script I have on the avatar (right now, I toggle the "isSpectator" manually for testing purposes, but in the future, it should be controlled by the target platform) using UnityEngine; public class AvatarRoleInitializer : MonoBehaviour { public bool isSpectator; [SerializeField] public GameObject leftHand, rightHand; private void Start() { if (!isSpectator) return; gameObject.AddComponent<Spectator>(); Destroy(leftHand); Destroy(rightHand); } } And the Spectator component does the following using Normal.Realtime; using UnityEngine; public class Spectator : MonoBehaviour { // Multiplayer private RealtimeView _realtimeView;
private void Awake() { // Store a reference to the RealtimeView for easy access _realtimeView = GetComponent<RealtimeView>(); }
private void Start() { // Call LocalStart() only if this instance is owned by the local client if (_realtimeView.isOwnedLocallyInHierarchy) LocalStart(); }
private void LocalStart() { // Request ownership of the Player and the character RealtimeTransforms GetComponent<RealtimeTransform>().RequestOwnership();
transform.position = Vector3.up * 5; transform.LookAt(Vector3.zero); // Look at center of scenery } } Even though I disable the XR Interaction Setup (which has the XROrigin) the spectator spawns at the XR Interaction Setup position It seems I got it working by setting the position of the XR Origin (XR Rig) to the desired position when the client connects as spectator