- Home /
Inherited network message not sending/receiving correctly
I'm using the new Unity 5 networking system (UNET) and NetworkServer and NetworkClient and their relative send functions to communicate between connections.
http://docs.unity3d.com/Manual/UNetMessages.html
This article talks about using a custom class which inherits from MessageBase to send customisable data via the send functions. I find no issue with sending/receiving messages using one layer of inheritance. So for example, the code below works fine.
public class InitialiseBoard_Message : MessageBase
{
public Vector2 board_Size;
public Tile_Info[] tile_List;
}
However, for ease, I've tried to add another layer of inheritance to the MessageBase to include data I'd mostly expect I require by all the messages I send regardless of what type of message it is.
public class Message_Base : MessageBase
{
public int client_ID;
public int player_Index;
}
public class InitialiseSpawn_Message : Message_Base
{
public Vector2 tile_Index;
public Vector2 square_Index;
}
private void Receive_Message_Client(NetworkMessage message)
{
Network_Message.InitialiseSpawn_Message network_Message = message.ReadMessage<Network_Message.InitialiseSpawn_Message >();
}
But when I receive this data either via the server or the network client, the data is incorrect like the variable has just been instantiated rather than "read" into. Is this something to do with the serialisation of the message? Or do the network message classes just not like inherited classes?
If it is because the message needs custom serialisation, how would I go about doing that?
Thank you!