diff --git a/Assets/Mirror/Runtime/MessagePacker.cs b/Assets/Mirror/Runtime/MessagePacker.cs index e505ec1fb..39dfb1a22 100644 --- a/Assets/Mirror/Runtime/MessagePacker.cs +++ b/Assets/Mirror/Runtime/MessagePacker.cs @@ -25,6 +25,11 @@ public static int GetId() where T : IMessageBase return typeof(T).FullName.GetStableHashCode() & 0xFFFF; } + public static int GetId(Type type) + { + return type.FullName.GetStableHashCode() & 0xFFFF; + } + // pack message before sending [EditorBrowsable(EditorBrowsableState.Never), Obsolete("Use Pack instead")] public static byte[] PackMessage(int msgType, MessageBase msg) @@ -54,7 +59,7 @@ public static byte[] Pack(T message) where T : IMessageBase try { // write message type - int msgType = GetId(); + int msgType = GetId(message.GetType()); writer.WriteUInt16((ushort)msgType); // serialize message into writer diff --git a/Assets/Mirror/Runtime/NetworkConnection.cs b/Assets/Mirror/Runtime/NetworkConnection.cs index e85f692f4..8828b0cf5 100644 --- a/Assets/Mirror/Runtime/NetworkConnection.cs +++ b/Assets/Mirror/Runtime/NetworkConnection.cs @@ -334,7 +334,7 @@ internal bool InvokeHandler(int msgType, NetworkReader reader) /// public bool InvokeHandler(T msg) where T : IMessageBase { - int msgType = MessagePacker.GetId(); + int msgType = MessagePacker.GetId(msg.GetType()); byte[] data = MessagePacker.Pack(msg); return InvokeHandler(msgType, new NetworkReader(data)); }