Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

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:
    36,762
    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:
    36,762
    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:
    36,762
    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.
     
  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.
     
    FM-Productions likes 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.