Mirror-Multiplayer-Tutorials icon indicating copy to clipboard operation
Mirror-Multiplayer-Tutorials copied to clipboard

Mirror Message System Not working with Unity 2020.2 and the latest version of Mirror. Found a Fix.

Open AinsRuby opened this issue 4 years ago • 0 comments

public class Notification : MessageBase { public string content; }

public class MessagesTest : MonoBehaviour
{
    [SerializeField] private TMP_Text notificationsText = null;

    private void Start()
    {
        if (!NetworkClient.active) { return; }

        NetworkClient.RegisterHandler<Notification>(OnNotification);
    }

    private void OnNotification(NetworkConnection conn, Notification msg)
    {
        notificationsText.text += $"\n{msg.content}";
    }
}

This had two errors, MessageBase became Deprecated, so needed to be changed to NetworkMessage. Once it was changed to NetworkMessage, it had another error, "The type 'Notification' must be a non-nullable value type in order to use it as parameter 'T' in the generic type or method 'NetworkClient.RegisterHandler<T>" To fix that, I changed

public class Notification : MessageBase { public string content; } to public struct Notification : MessageBase { public string content; }

AinsRuby avatar Jan 01 '21 19:01 AinsRuby