Forum Discussion
Avias8
1 year agoExplorer
Avatars with Custom Matchmaking
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:
Setup
- Networking Framework: Photon Fusion
- Custom Matchmaking: Implemented using the CustomMatchmaking Building Block.
- Avatar Spawning: Using the Networked Avatar building block, which is part of the Oculus Multiplayer Building Blocks package.
Problem
When creating or joining a room:
- The avatars fail to spawn because _networkRunner in AvatarSpawnerFusion remains null.
- The _sceneLoaded flag in AvatarSpawnerFusion also remains false, which blocks the avatar spawning process.
Debugging Attempts
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:
- Believing that the issue is related to the differences between CustomMatchMaking and Auto Matchmaking/Fusion Bootstrap, I looked into things and discovered the BBEvent is never fired in the CustomMatchMaking script.
- I created a integration to subscribed to FusionBBEvents.OnSceneLoadDone to trigger avatar spawning after a scene is loaded.
- Unfortunately, this event never fires, likely because Fusion isn't loading a new scene when creating or joining a room.
Manual Assignment:
- I manually assigned the NetworkRunner reference to AvatarSpawnerFusion.
- Even with this, _networkRunner still appears as null within AvatarSpawnerFusion, preventing avatars from spawning.
Mark Scene as Loaded:
- I added a method to manually mark the scene as loaded within AvatarSpawnerFusion.
- Called this method after the room creation or joining process, but it didn’t resolve the issue.
Code Snippets
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.
Observations
- Avatar Spawning Dependencies: AvatarSpawnerFusion relies on _networkRunner and _sceneLoaded being set, which isn’t happening under these conditions.
- Manual Fixes: Attempting to manually assign networkRunner and set _sceneLoaded to true hasn’t resolved the issue.
Questions
- How can I ensure that the BBEvents are properly integrated in CustomMatchMakingafter creating or joining a room?
- Has anyone successfully integrated the Oculus Multiplayer Building Blocks with Photon Fusion for avatar spawning? If so, how did you handle avatar integration with rooms?
Any help or guidance would be greatly appreciated! I’m happy to provide more details or code snippets if needed.
Thanks in advance!
1 Reply
Replies have been turned off for this discussion
- ashfaqmhdHonored Guest
any solution
Quick Links
- Horizon Developer Support
- Quest User Forums
- Troubleshooting Forum for problems with a game or app
- Quest Support for problems with your device
Other Meta Support
Related Content
- 10 months ago
- 1 year ago
- 8 months ago