Question by
ViniciusLucas · Oct 08, 2020 at 06:49 PM ·
networkingmultiplayermirror
Mirror rpc executing before everything else
I've created a UI button that toggles the ready state of the client who clicks on it. For him, it updates correctly, but for the other clients, it executes the rpc method first, and than, updates the ready state value. So for the client who clicks, works fine, but for the other clients, shows the outdated state (if the client is ready, it shows not ready).
I tried to use coroutine to wait for a second, and it worked fine, updated correctly, but it creates a delay that I don't want. So I belive that the problem is that for the client who clicks on the button, the rpc method is read after everything else, but for the other clients, it's the first thing that is read by the system. Is there a way to change that?
using Mirror;
using TMPro;
using UnityEngine;
public class LobbyController : NetworkBehaviour {
#pragma warning disable 0649
[SerializeField] private TMP_Text[] _textsName;
[SerializeField] private TMP_Text[] _textsStatus;
#pragma warning restore 0649
private CustomNetworkRoomManager _room;
private CustomNetworkRoomPlayer _player;
private void Start() => _room = NetworkManager.singleton as CustomNetworkRoomManager;
public void ReadyButton() {
_player.CmdChangeReadyState(!_player.readyToBegin);
SetPlayersStatus();
}
public void SetPlayer(CustomNetworkRoomPlayer player) {
_player = player;
SetPlayersStatus();
}
private void SetPlayersStatus() {
if (isServer) RpcSetPlayersStatus();
else CmdSetPlayersStatus();
}
[Command(ignoreAuthority = true)]
private void CmdSetPlayersStatus() => RpcSetPlayersStatus();
[ClientRpc]
private void RpcSetPlayersStatus() {
for (int p = 0; p < 5; p++) {
if(p < _room.roomSlots.Count) {
_textsName[p].text = "Test";
if (_room.roomSlots[p].readyToBegin) {
_textsStatus[p].color = Color.green;
_textsStatus[p].text = "Ready";
} else {
_textsStatus[p].color = Color.red;
_textsStatus[p].text = "Not Ready";
}
} else {
_textsName[p].text = "Empty";
_textsStatus[p].text = "";
}
}
}
}
Comment