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. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

JsonUtility custom scruct array

Discussion in 'Scripting' started by vinhui_, Dec 14, 2015.

  1. vinhui_

    vinhui_

    Joined:
    Jan 29, 2014
    Posts:
    13
    Hi,

    Im trying out the new JsonUtility but im having some issues. I have an array of a custom type but it fails to deserialize and thows "Unexpected node type." I tried making it a class, deriving it from UnityEngine.Object, even ScriptableObject but it didnt work. The type has the System.Serializable attribute.
     
  2. lordofduct

    lordofduct

    Joined:
    Oct 3, 2011
    Posts:
    8,380
    Don't inherit from ScriptableObject or UnityEngine.Object. Those are unity objects that are serialized and deserialized in a much different way.

    Json serialization is more data-centric than unity object centric.

    What was the struct you tried to serialize/deserialize? Were any of its fields a type that wasn't easily serialized, or a unity object itself?
     
  3. vinhui_

    vinhui_

    Joined:
    Jan 29, 2014
    Posts:
    13
    the struct just contains 3 string fields
     
  4. superpig

    superpig

    Drink more water! Unity Technologies

    Joined:
    Jan 16, 2011
    Posts:
    4,614
    Hi,

    Can you please post both the JSON you are trying to deserialize, and the struct you are trying to deserialise it into?
     
  5. floky

    floky

    Joined:
    Oct 6, 2010
    Posts:
    273