Search Unity

Question SendNamedMessage does not allow sending messages within the host, unlike RPC

Discussion in 'Netcode for GameObjects' started by CodeSmile, Sep 30, 2022.

  1. CodeSmile

    CodeSmile

    Joined:
    Apr 10, 2014
    Posts:
    5,970
    I am testing custom named messages while being the host in playmode and no clients connected. I expected the custom messages to work like my RPC pair: SendToServerRPC which then calls SendToClientRPC. Those work fine with just within the host, since the host is both server and client.

    I was surprised to find I couldn't get this to work with named custom messages. I even pasted the CustomNamedMessageHandler verbatim from the docs and added logging to it: https://docs-multiplayer.unity3d.com/netcode/current/advanced-topics/message-system/custom-messages

    But no matter what I try, SendNamedMessage cannot be used to send a message on a host (as the server) to the host (as a client) like RPC allows me to do.

    I assume this is because SendNamedMessage determines that it needn't send the message to itself. I can't say if this is by design - on some level it makes perfect sense, but on the other hand, why would I be able to exchange messages on the host with RPC but won't be able to do this with custom named messages?

    At a minimum it would be welcome for testing, though I thought that RPC are implemented using messaging, so I am surprised that the higher-level system allows you to do what the lower-level system cannot do. Or did I miss anything here?