Hello,
I encounter a sync problem on a certain ClientRpc function which does not want to be done on the client side.
To resume the code, in the multiplayer scene I have an object that contains the script “MultiUIManager” wich its start function will only be used by the server and that will recover all the players in the scene.
In the recovery function at certain times RpcClient functions will be called, but the problem is that these RpcClients functions are not called client side and I do not understand why ( when i try a lot of time, sometimes it’s works ).
I made a little schema in case:
For the code in MultiUIManager :
void Start ( )
{
if ( isServer )
{
paw.getPlayer ( );
}
}
In PawControlMulti
[Server]
public void getPlayer ( )
{
nbrPlay.Clear ( );
List<PlayerMulti> getP = allPlayer;
List<int> getNbrP = nbrPlay;
int nbrPlayer = 0;
foreach ( PlayerMulti thisPlayer in FindObjectsOfType<PlayerMulti> ( ) )
{
getP.Add ( thisPlayer );
getP [ nbrPlayer ].IdPlayer = nbrPlayer;
getP [ nbrPlayer ].CanDetect = false;
getP [ nbrPlayer ].CanPlay = false;
getNbrP.Add ( 0 );
RpcIniPlayer ( thisPlayer.gameObject, nbrPlayer );
nbrPlayer ++;
}
if ( nbrPlayer < Prototype.NetworkLobby.LobbyManager.s_Singleton.numPlayers )
{
getP.Clear ( );
getNbrP.Clear ( );
canOpen = false;
RpcClearNbrP ( );
StartCoroutine ( waitRecheck ( ) );
return;
}
Debug.Log ( "server in PawMulti" );
RpcPassPlayer ( nbrPlayer );
currentPlayer = Random.Range ( 0, nbrPlayer );
enableAPlayer ( );
canOpen = true;
MultiUIManager.MUIManager.StartIniPlayer ( getP );
}
And for the 3 RpcClients fonction :
[ClientRpc]
void RpcIniPlayer ( GameObject thisPlayer, int thisID )
{
Debug.Log ( "Client in RpcIniPlayer" );
PlayerMulti thisP = thisPlayer.GetComponent <PlayerMulti> ( );
allPlayer.Add ( thisP );
nbrPlay.Add ( 0 );
thisP.IdPlayer = thisID;
thisP.CanDetect = false;
thisP.CanPlay = false;
}
[ClientRpc]
void RpcClearNbrP ( )
{
Debug.Log ( "Client in ClearNbrP" );
allPlayer.Clear ( );
nbrPlay.Clear ( );
}
[ClientRpc]
void RpcPassPlayer ( int nbrPlayer )
{
Debug.Log ( "Client in RpcPassPlayer" );
List<Image> setPass = passPlayer;
Vector2 rectParent = getPassInfo.GetComponent<RectTransform> ( ).sizeDelta;
Vector2 thisRect;
GameObject getCurrImg;
float getSpace = ( float ) ( rectParent.x - PassPrefb.GetComponent<RectTransform> ( ).sizeDelta.x * nbrPlayer ) / ( nbrPlayer - 1 );
int a;
for ( a = 0; a < nbrPlayer; a++ )
{
getCurrImg = ( GameObject ) Instantiate ( PassPrefb, getPassInfo );
thisRect = getCurrImg.GetComponent<RectTransform> ( ).sizeDelta;
getCurrImg.GetComponent<Transform> ( ).localPosition = new Vector2 ( -rectParent.x / 2 + thisRect.x / 2 + a * thisRect.x + getSpace * a, rectParent.y / 2 - thisRect.y / 2 );
getCurrImg.GetComponent<Image> ( ).sprite = StopPass;
setPass.Add ( getCurrImg.GetComponent<Image> ( ) );
}
}
As a result none of its three RpcClients functions want to work, while those used in the player script work.
I do not know if it is due to the fact that the client does not initialize in time? but it would seem odd to me that I can recover all the players in my variable List (and there is a check if there is lack of players).
And I hope this is not due to the fact that the object is present by default in the multi scene, it would be a bit abused.
Finally, if a few to a track it would help me greatly;
Thank you.