Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Third Party Mirror - No writer found for Commander. Use a type supported by Mirror or define a custom writer

Discussion in 'Multiplayer' started by cerestorm, Aug 29, 2021.

  1. cerestorm

    cerestorm

    Joined:
    Apr 16, 2020
    Posts:
    656
    I'm having a bit of a problem with Mirror at the moment. I've written a custom serialiser for a couple of classes that implement the same interface. The issue is Weaver is complaining that a couple of enums and a class within these classes should have their own custom writers, while another enum and other classes are fine. This is the custom serialiser class:
    Code (CSharp):
    1.  
    2. public static class EventDetailSerialiser
    3. {
    4.     const byte SERVER_ACTION_EVENT_DETAIL = 1;
    5.     const byte PLAYER_ACTION_EVENT_DETAIL = 2;
    6.  
    7.     public static void WriteItem(this NetworkWriter writer, EventDetail eventDetail)
    8.     {
    9.         if (eventDetail is ServerActionEventDetail serverActionEventDetail)
    10.         {
    11.             writer.WriteByte(SERVER_ACTION_EVENT_DETAIL);
    12.             writer.Write<PlayerUpdateFlags>(serverActionEventDetail.playerUpdateFlags);
    13.             writer.Write<ServerActionEventFlags>(serverActionEventDetail.actionEventFlags);
    14.             writer.WriteString(serverActionEventDetail.text);
    15.             writer.Write<Commander>(serverActionEventDetail.commander);
    16.             writer.WriteList<PathDetail>(serverActionEventDetail.pathDetails);
    17.             writer.WriteList<Location>(serverActionEventDetail.vicinityLocations);
    18.  
    19.         }
    20.         else if (eventDetail is PlayerActionEventDetail playerActionEventDetail)
    21.         {
    22.             writer.WriteByte(PLAYER_ACTION_EVENT_DETAIL);
    23.             writer.WriteVector2Int(playerActionEventDetail.position);
    24.             writer.Write<ScreenType>(playerActionEventDetail.screenType);
    25.         }  
    26.     }
    27.  
    28.     public static EventDetail ReadItem(this NetworkReader reader)
    29.     {
    30.         byte type = reader.ReadByte();
    31.         switch (type)
    32.         {
    33.             case SERVER_ACTION_EVENT_DETAIL:
    34.                 return new ServerActionEventDetail
    35.                 {
    36.                     playerUpdateFlags = reader.Read<PlayerUpdateFlags>(),
    37.                     actionEventFlags = reader.Read<ServerActionEventFlags>(),
    38.                     text = reader.ReadString(),
    39.                     commander = reader.Read<Commander>(),
    40.                     pathDetails = reader.ReadList<PathDetail>(),
    41.                     vicinityLocations = reader.ReadList<Location>()
    42.                 };
    43.             case PLAYER_ACTION_EVENT_DETAIL:
    44.                 return new PlayerActionEventDetail
    45.                 {
    46.                     position = reader.ReadVector2Int(),
    47.                     screenType = reader.Read<ScreenType>()
    48.                 };
    49.             default:
    50.                 throw new Exception($"Invalid message type {type}");
    51.         }
    52.     }
    53. }
    54.  
    PlayerUpdateFlags and ServerActionEventFlags are the enums causing issues. They are flags but I don't see that as the problem as changing the enum that works (ScreenType) to flags doesn't cause an error. I've changed to treating the enums as ints for now to get around the error.

    For the failing class, Commander, I don't think it's the class itself that's the issue as I've tried creating a new class and struct and they also cause the same error. The other classes, PathDetail and Location are fine.

    Any ideas on how to fix this? A search did turn up this issue and I wondered if it was related: https://github.com/vis2k/Mirror/issues/2579

    I'm running my project in Unity 2020.3.8f1 with Mirror 44.0.2.
     
    Last edited: Aug 29, 2021
    mingkimlow likes this.