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

Guid serialization and Burst

Discussion in 'Burst' started by tonytopper, Sep 23, 2022.

  1. tonytopper

    tonytopper

    Joined:
    Jun 25, 2018
    Posts:
    199
    Guid is Burstable. Since Unity doesn't serialize Guid on its own I have been serializing Guid to a string using OnBeforeSerialize and OnAfterDeserialize. However, a string isn't Burstable and I can't find a way to get Burst to ignore these fields used only for serialization.

    Is there anything I can easily serialize a Guid with? Either will Unity's built-in serialization or the prior-mentioned callbacks that is also compatible with Burst?
     
  2. Zuntatos

    Zuntatos

    Joined:
    Nov 18, 2012
    Posts:
    612
    What's the containing code like? Assuming it's ISerializationCallbackReceiver you're talking about, that only works on classes I think, so that's something Burst isn't going to touch anyway. Which confuses me a little with this problem. You'd pass the Guid or some inner struct to Burst and that would not contain the string field that's on the class, so presumably it would be fine with Burst.
     
  3. tonytopper

    tonytopper

    Joined:
    Jun 25, 2018
    Posts:
    199
    Ahhh ... I had switched this code from a class to a struct as I migrated to Jobs and Burst.

    If I remember correctly, the serialization callbacks were still getting called though, so I mistakenly thought that worked. But as you point out and the ISerializationCallbackReceiver docs state "The callback interface only works with classes. It does not work with structs."

    This also answers another problem I am working on.

    Thanks for the reply.
     
  4. Deleted User

    Deleted User

    Guest

    you could create a custom guid struct or class that's serializable and has operators that convert it to/from Guid.