Network Messages
To send simple custom network messages you can use the functions that are inside
These functions are using Netcode's NamedMessage in the background, but adds some extra validations.
For networked objects it is recommended to NOT use direct messages, and instead use the SNetworkActions which will save you a lot of lines of code. Direct messages can be used inside generic managers or for initialization.
ListenMsg and UnlistenMsg
Use ListenMsg("id", callback) to listen for incoming network messages.
Send vs SendAll
Send allows you to send the message to a client of your choice (if called from the server) or to send to the server (if called from client).
SendAll can only be called from the server and will send to all connected clients.
SendInt, SendBool, SendFloat, SendBytes...
These function are used to send basic types as the only data in the message.
SendObject
To send any class or struct (must inherit from INetworkSerializable). See original Netcode documentation to understand serialization: INetworkSerializable
Note that it is not possible to send GameObjects or class that contain non-serializable fields.
SendBuffer
Use this function to send a FastBufferWriter, this is the original Netcode way to use namedMessages. Make sure to Dispose() the buffer if you created a new one.
Forward and ForwardAll
Forward should only be called by the server. And allows you to resend a message you receive from a client to another client (or to all other clients).
Last updated