Question by
talhacagatayisik · Jan 19, 2021 at 03:31 PM ·
networkingunity multiplayer
Mirror Networking; How to Pass/Sync c# actions ?
Since you can not pass actions as parameters to commands and rpc calls, how would you sync actions ? My main goal is to find an easy and generic way for objects to easily do actions from their local player. Something like:
_localPlayer.RunFromLocalToAllPlayers(()=>
{
//MyAction
});
Local Player having these methods:
private Action _callbackForAllPlayers;
public void RunFromLocalPlayerToAllPlayers(Action callback)
{
_callbackForAllPlayers = callback;
Debug.Log(_callbackForAllPlayers);
CmdRunFromLocalPlayerToAllPlayers();
}
[Command]
private void CmdRunFromLocalPlayerToAllPlayers()
{
Debug.Log($"Running on server");
RpcRunFromLocalPlayer();
}
[ClientRpc]
private void RpcRunFromLocalPlayer()
{
Debug.Log($"Running on client");
_callbackForAllPlayers?.Invoke();
Debug.Log(_callbackForAllPlayers);
}
and of course that local Action variable is being null on other clients since i can not sync it or pass it as parameter.
Comment
Your answer
![](https://koobas.hobune.stream/wayback/20220613023540im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
OnLobbyServerSceneLoadedForPlayer not called for client 1 Answer
NetworkMigrationManager does not work with unet matchmaker 0 Answers
What's wrong with my script ? 0 Answers
UNET Online Match Making? 1 Answer
Bullets not spawning in other clients but its spawning on the client that shot it. 1 Answer