asadm / playroom-unity

9 stars 1 forks source link

mock mode bug: #29

Closed asadm closed 5 months ago

asadm commented 5 months ago

when the mockPlayer onJoin is fired: Screenshot 2024-01-14 at 10 47 14 AM

momintlh commented 5 months ago

This is not a mock-mode bug. It's happening inside GameManager, easy to reproduce by calling OnPlayerJoin(Addplayer) multiple times, as we have a hardcoded playerID/key for "mockPlayer", it tries to add the create a new entry with the same key in the dictionary.

This is the part of the code in the sample gamemanager.cs, I used a dictionary (in the demo) just to make a connection between playerId and its gameObject.. removing the dictionary works or we can just give a custom/random id when creating mockMode Player.

// optional dictionary,
 private static Dictionary<string, GameObject> PlayerDict = new();

// calling this multiple times inside mockmode,
PlayroomKit.OnPlayerJoin(AddPlayer);
PlayroomKit.OnPlayerJoin(AddPlayer);

// inside AddPlayer:
 PlayerDict.Add(player.id, playerObj); // This will raise error the second time AddPlayer callback is invoked in mockmode because player.id is always "mockPlayer" 

inside playroomkit.cs we have defined:

private const string PlayerId = "mockPlayer";

@SaadBazaz What do you suggest?

SaadBazaz commented 5 months ago

@momintlh Okay I understand. But question; once the player 1 has joined (in this case, the ID being mockPlayer), why does this callback fire again in the first place? 🤔

Shouldn't it fire just once?

What's triggering it?

momintlh commented 5 months ago

@momintlh Okay I understand. But question; once the player 1 has joined (in this case, the ID being mockPlayer), why does this callback fire again in the first place? 🤔

Shouldn't it fire just once?

What's triggering it?

In the previous example OnPlayerJoin(AddPlayer) is being called twice.