Issue with Fusion 106

Options

Hello,   

I'm getting an issue with the below code which matches what is shown in Fusion 106 about RPCs.

Specifically, the check to see if the message info is from the local player:

if (info.Source == Runner.Simulation.LocalPlayer)

If I run a server, this works correctly, but if I run in host mode, when the host sends the RPC it recognizes it as if the other player had sent it. Looking at the API, it seems like it should also include in the RPC tag "HostMode = RpcHostMode.SourceIsHostPlayer".

Just want to make sure I'm understanding correctly. Thanks for any clarification.


private void Update()

  {

    if (Object.HasInputAuthority && Input.GetKeyDown(KeyCode.R))

    {

      RPC_SendMessage("Hey!");

    }

  }


  [Rpc(RpcSources.InputAuthority, RpcTargets.All)]

  private void RPC_SendMessage(string message, RpcInfo info = default)

  {

    if (_messages == null)

      _messages = FindObjectOfType<Text>();

    if (info.Source == Runner.Simulation.LocalPlayer)

      message = $"You said: {message}\n";

    else

      message = $"Other player said {message}\n";

    _messages.text += message;

  }

Answers

  • jcnewts
    Options

    Update:

    Is there a downside to just checking:

    if (info.IsInvokeLocal) instead of  if (info.Source == Runner.Simulation.LocalPlayer)

    to determine if it was sent by the local player, and then not having to worry about the extra "HostMode = RpcHostMode.SourceIsHostPlayer" tag?