Skip to main content
2 of 2
added 12 characters in body

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.