12-15-2024 11:53 AM
Hi everyone,
I’m currently facing an issue with spawning avatars when using Custom Matchmaking in a project built on Photon Fusion using the Meta Building Blocks. Specifically, avatars fail to spawn when a player creates or joins a room. I've spent a lot of time debugging and testing, but I still can't figure out what's wrong. Here are the details:
When creating or joining a room:
Here’s what I’ve tried:
Debug Logs: I added debug statements to check the status of _networkRunner, _sceneLoaded, and _entitlementCompleted. Within the AvatarSpawnerFusion class. Even after the room is created or joined, _networkRunner remains null and _sceneLoaded is false.
private IEnumerator SpawnAvatarRoutine()
{
while (_networkRunner == null || !_sceneLoaded || !_entitlementCompleted)
{
Debug.Log("Network runner null?:" + (_networkRunner == null));
Debug.Log("Scene loaded status:" + _sceneLoaded);
Debug.Log("Entitlement completed status:" + _entitlementCompleted);
yield return null;
}
Example Debug Output:
Network runner null?: True Scene loaded status: False Entitlement completed status: True
FusionBBEvents:
Manual Assignment:
Mark Scene as Loaded:
Here’s an example of how I’m integrating Custom Matchmaking with AvatarSpawnerFusion:
using UnityEngine;
using Meta.XR.MultiplayerBlocks.Shared;
using Meta.XR.MultiplayerBlocks.Fusion;
using Fusion;
using System.Linq;
public class CustomMatchmakingIntegration : MonoBehaviour
{
[SerializeField] private CustomMatchmaking matchmaking;
[SerializeField] private AvatarSpawnerFusion avatarSpawner; // Assign via Inspector
[SerializeField] private NetworkRunner networkRunner; // Ensure AvatarSpawnerFusion is in the scene
private void OnEnable()
{
if (matchmaking != null)
{
matchmaking.onRoomCreationFinished.AddListener(OnRoomCreated);
matchmaking.onRoomJoinFinished.AddListener(OnRoomJoined);
}
}
private void OnDisable()
{
if (matchmaking != null)
{
matchmaking.onRoomCreationFinished.RemoveListener(OnRoomCreated);
matchmaking.onRoomJoinFinished.RemoveListener(OnRoomJoined);
}
// Unsubscribe from BB events if needed
FusionBBEvents.OnSceneLoadDone -= OnSceneLoadDone;
}
private void OnRoomCreated(CustomMatchmaking.RoomOperationResult result)
{
if (result.IsSuccess)
{
if (networkRunner != null)
{
// Since no OnSceneLoadDone will fire if no scene is loaded:
avatarSpawner.MarkSceneLoaded(networkRunner);
avatarSpawner.SpawnAvatar();
}
}
else
{
Debug.LogWarning("Room creation failed: " + result.ErrorMessage);
}
}
private void OnRoomJoined(CustomMatchmaking.RoomOperationResult result)
{
if (result.IsSuccess)
{
// Successfully joined a room. Find the active runner.
if (networkRunner != null)
{
// Subscribe to OnSceneLoadDone event from BBEvents
FusionBBEvents.OnSceneLoadDone += OnSceneLoadDone;
}
}
else
{
Debug.LogWarning("Room join failed: " + result.ErrorMessage);
}
}
private void OnSceneLoadDone(NetworkRunner runner)
{
if (runner == networkRunner)
{
Debug.Log("Scene loaded for our runner. Spawning avatar now...");
// If AvatarSpawnerFusion requires scene loaded and runner set:
// avatarSpawner.MarkSceneLoaded(networkRunner);
// Or if it’s ready to spawn now:
avatarSpawner.SpawnAvatar();
// Unsubscribe if you only needed this once
FusionBBEvents.OnSceneLoadDone -= OnSceneLoadDone;
}
}
}
Despite this integration, the avatars still fail to spawn due to _networkRunner being null.
Any help or guidance would be greatly appreciated! I’m happy to provide more details or code snippets if needed.
Thanks in advance!
Did this answer your question? If it didn’t, use our search to find other topics or create your own and other members of the community will help out.
If you need an agent to help with your Meta device, please contact our store support team here.
Having trouble with a Facebook or Instagram account? The best place to go for help with those accounts is the Facebook Help Center or the Instagram Help Center. This community can't help with those accounts.
Check out some popular posts here:
Getting Help from the Meta Quest Community
Tips and Tricks: Charging your Meta Quest Headset