Automatic Serializers

Anytime you use a type within a communication Fish-Networking automatically recognizes you wish to send the type over the network, and will create a serializer for it. You do not need to perform any extra steps for this process, but if you would like to exclude fields from being serialized use [System.NonSerialized] above the field.

For example, Name and Level will be sent over the network but not Victories.

public class PlayerStat
{
    public string Name;
    public int Level;
    [System.NonSerialized]
    public int Victories;
}

[ServerRpc]
public void RpcPlayerStats(PlayerStat stats){}

Fish-Networking is also capable of serializing inherited values. In the type MonsterStat below, Health, Name, and Level will automatically serialize.

public class Stat
{
    public float Health;
}
public class MonsterStat : Stat
{
    public string Name;
    public int Level;
}

In very rare cases a data type cannot be automatically serialized; a Sprite is a good example of this. It would be very difficult and expensive to serialize the actual image data and send that over the network. Instead, you could store your sprites in a collection and send the collection index, or perhaps you could create a custom serializer.

Last updated