Closed asadm closed 5 months ago
Hello, I'm the one who reported the problem, so here are the various code extracts that are directly linked to Playroom.
First of all, here's a method that's called when I click on the Multiplayer button. When I click on it, it opens a scene in which the characters are supposed to appear:
public void Multiplayer()
{
PlayroomKit.InsertCoin(() =>
{
SceneManager.LoadScene("TestScene");
}, new PlayroomKit.InitOptions()
{
maxPlayersPerRoom = 2
});
}
And on the second scene, there's a GameManager, in this GameManager, it contains all the multiplayer functionality, character appearance and synchronization:
private void Awake()
{
// if single player, create player game object
if (PlayroomKit.MyPlayer() == null)
{
// create player game object
GameObject playerObj = Instantiate(playerPrefab, new Vector2(Random.Range(-1.5f, 1.2f), Random.Range(0, -1)), Quaternion.identity);
// set camera follow player
cinemachineVirtualCamera.Follow = playerObj.transform;
// dont destroy player game object when load new scene
DontDestroyOnLoad(playerObj);
}
else
{
Debug.Log("new player : " + PlayroomKit.MyPlayer().GetProfile().name);
// if multiplayer, add player to the game;
PlayroomKit.OnPlayerJoin(AddPlayer);
}
}
private void AddPlayer(PlayroomKit.Player player)
{
// create player game object
GameObject playerObj = (GameObject)Instantiate(playerPrefab, new Vector2(Random.Range(-1.5f, 1.2f), Random.Range(0, -1)), Quaternion.identity);
// dont destroy player game object when load new scene
DontDestroyOnLoad(playerObj);
// set player color
playerObj.GetComponentInChildren<SpriteRenderer>().color = player.GetProfile().color;
Debug.Log(player.GetProfile().name + " joined the game!" + " id: " + player.id);
// add player to player list
PlayerDict.Add(player.id, playerObj);
players.Add(player);
playerGameObjects.Add(playerObj);
playerJoined = true;
// remove player from player list when player quit
player.OnQuit(RemovePlayer);
// set camera follow player
if (player.Equals(PlayroomKit.MyPlayer()))
{
cinemachineVirtualCamera.Follow = playerObj.transform;
}
}
and of course, before doing the last update, everything works, but I hope that what I have sent you is enough for you to help me.
@Huskago Reproducing this. In the meanwhile, can you test on the latest version of PlayroomKit from the one you currently have? There could possibly be an update.
But my problem arose when I upgraded to the latest version of Playroom, v0.0.10, because before doing so, everything was working fine. Before upgrading, I was at v0.0.9.
Until we resolve this, you can rollback to 0.0.9. There may be less features, but apparently it's stable.
The issue was with how we were handling the callback with OnPlayerJoin(), basically they are not being invoked after added to the list of callbacks. The real issue is how this was working in previous releases as this was never changed since the first release lol. I have tested it with v0.0.10 and have the fix, will open a PR =)
hey @Huskago can you test this https://mmntlh.itch.io/playroom-demo.
From discord: