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

Image resource ids keep changing

Discussion in 'Editor & General Support' started by gennen, Apr 19, 2017.

  1. gennen

    gennen

    Joined:
    Feb 5, 2013
    Posts:
    18
    I'm delving into the exciting world of serializing and saving things for the first time and running into a frustrating issues. I have serialized classes that I'm saving out using standard json methods and some of the variables in those classes are Images. Somewhat to my surprise, saving and loading those worked since what I assume to be the local resource ID is being properly serialized and deserialized. Unfortunately, these saves are corrupted whenever I change the game's build, presumably because the local ids of the images are being reinitialized under the hood. My next step to prevent this issue would be to stop assigning Images and start assigning manual index references to some Image-Library master script, but that seems like exactly the sort of thing the engine should be doing for me. Is there a way to tell Unity to stop changing resource IDs once assigned, or some similar solution to this problem?
     
  2. mikael_juhala

    mikael_juhala

    Joined:
    Mar 9, 2015
    Posts:
    247
    What are you referring to with "local resource ID" and "chane the game's build"?

    Anyway, you should be able to work with the asset GUIDs, since they should not change unless the assets are moved in Finder/Explorer/etc.
     
  3. gennen

    gennen

    Joined:
    Feb 5, 2013
    Posts:
    18
    What I mean is that when I serialize and export to JSON I get things like: "CombatSprite":{"instanceID":10632} And then when I re-serialize it, it points to the correct image. But when I rebuild the project (Build&Run) all those instanceID's now point to nothing and all my images are blank :( It sounds like maybe my best option is to write a translation layer that uses the GUID.
     
  4. zombiegorilla

    zombiegorilla

    Moderator

    Joined:
    May 8, 2012
    Posts:
    8,969
    Where are the images stored?
     
  5. gennen

    gennen

    Joined:
    Feb 5, 2013
    Posts:
    18
    Just inside Assets/Textures