Skip to content

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

Description

@AinsRuby

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"
To fix that, I changed

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

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions