Search Unity

  1. We are migrating the Unity Forums to Unity Discussions. On July 12, the Unity Forums will become read-only. On July 15, Unity Discussions will become read-only until July 18, when the new design and the migrated forum contents will go live. Read our full announcement for more information and let us know if you have any questions.

MessagePack Serializer NOT Working In Unity

Discussion in 'Scripting' started by allencook200, Apr 27, 2021.

  1. allencook200

    allencook200

    Joined:
    Oct 2, 2020
    Posts:
    178
    So I downloaded the MessagePack unitypackage, and I'm trying to serialize a class object, and it just is not working at all

    Code (CSharp):
    1. [MessagePackObject]
    2. public class Json_ClientTickUpdate
    3. {
    4.     [Key(0)]
    5.     public List<StoredData_ConnectedPlayer_Limited> Entities_Player = new List<StoredData_ConnectedPlayer_Limited>();
    6.  
    7.     [Key(1)]
    8.     public List<StoredData_Car>                     Entities_Car    = new List<StoredData_Car>();
    9.  
    10.     [Key(2)]
    11.     public List<StoredData_Entities>                Entities        = new List<StoredData_Entities>();
    12.  
    13. }
    Code (CSharp):
    1. var newSerialized = MessagePackSerializer.Serialize(_Json_ClientTickUpdate);
    Which gives me the error:
    Code (CSharp):
    1. FormatterNotRegisteredException: Json_ClientTickUpdate is not registered in resolver: MessagePack.Resolvers.StandardResolver
    Any help is appreciated. This is EXTREMELY annoying.
     
  2. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    39,571
    This looks more like something to do with MessagePack than with Unity.

    Are you sure you have met all the criteria for using this package? I'd start with their docs first.

    Alternatively, when in Rome, act like a Roman and just use JSON. It works all day long.
     
  3. allencook200

    allencook200

    Joined:
    Oct 2, 2020
    Posts:
    178
    JSON is slow. It's taking up the entire frame when I try to serialize a single large object to prepare it to send over a network. Fast serialization is a requirement for me.

    I literally read the docs front and back, so I have no clue what I'm missing. I literally downloaded the package designed for unity.



    Does this look like something I need to do?
     
    Last edited: Apr 27, 2021
  4. allencook200

    allencook200

    Joined:
    Oct 2, 2020
    Posts:
    178
    So apparently you need to register your types before you try to serialize them, yet the documentation gives absolutely 0 advice on how to do this inside unity. The ZeroFormatter docs are literally just a copy paste of the MessagePack docs. This really sucks, that the devs literally just chose to make their documentation as hard to follow as possible. So many people have this issue and the dev just refuses to tell people how to fix it. Straight up awful documentation.
     
  5. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    39,571
    I nominate @allencook200 to rise far up above the teeming hordes of dirty non-documenting developers and become a TRUE OPEN SOURCE HERO!

    Seriously, if you have a moment, make some quick docs, just a little readme or something, add it to the repo and issue a pull request.

    If it's reasonable and the guy takes it, hey look at that, now you can add True Open Source Hero to your resume.
     
    grimmgames and Bunny83 like this.
  6. allencook200

    allencook200

    Joined:
    Oct 2, 2020
    Posts:
    178
    Okay so after about 11 hours with playing hide and seek with the docs, I got it working inside unity, but it's only working with API 4.x and not 2.0. Does that sound like a problem?
     
  7. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    39,571
    It certainly did not keep me awake with worry last night.

    I guess if I was the kinda person wanting to build with 2.0 then I might be worried.
     
    Willkuerlich likes this.
  8. hayone1

    hayone1

    Joined:
    May 20, 2017
    Posts:
    8
    I know this comment is appearing much later, but the docs actually do point out that this problem does exist when you target IL2CPP and a solution using a code generator. Simply navigate to the "AOT Code Generation (support for Unity/Xamarin)" section of the docs. You can also view a solution on medium from here.
     
    Willkuerlich and FM-Productions like this.
  9. allencook200

    allencook200

    Joined:
    Oct 2, 2020
    Posts:
    178
    Thank you for reviving a 9 month old post.

    It also had nothing to do with IL2CPP and just their poorly written examples.
    I got rid of messagepack months ago and wrote my own serializer.
     
  10. KillDashNine

    KillDashNine

    Joined:
    Apr 19, 2020
    Posts:
    461
    Took me about an hour to get it working. You need to read the Unity Support section of the docs, especially look at the sample configuration.

    Include StandardResolver and UnityResolver for basic data types support. Then add [MessagePackObject] annotations to your custom classes. Either use keys or keyAsPropertyName: true.

    Done.

    Oh yes and remember to install the thing using the provided .unitypackage. It didn't work using the zipfile.
     
  11. unity_85DE227145227FED1D02

    unity_85DE227145227FED1D02

    Joined:
    Oct 4, 2023
    Posts:
    1
    Hello, I got Message Pack to work in unity but it doesn't work on my phone. I received the error message: FormatterNotRegisteredException: Playerdata is not registered in resolver: MessagePack.Resolvers.StaticCompositeResolver
     
  12. Willkuerlich

    Willkuerlich

    Joined:
    Sep 23, 2014
    Posts:
    15
    Chances are high mobile builds are subject to AOT-compilation issues