cancel
Showing results for 
Search instead for 
Did you mean: 

Avatars Not Spawning When Creating or Joining Rooms with Custom Matchmaking

Avias8
Explorer

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:

  1. 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  
      
  2. 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.
  3. Manual Assignment:

    • I manually assigned the NetworkRunner reference to AvatarSpawnerFusion.
    • Even with this, _networkRunner still appears as null within AvatarSpawnerFusion, preventing avatars from spawning.
  4. 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

  1. How can I ensure that the BBEvents are properly integrated in CustomMatchMakingafter creating or joining a room?
  2. 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!

0 REPLIES 0
Still need help?

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

Tips and Tricks: Help with Pairing your Meta Quest

Trouble With Facebook/Instagram Accounts?