Search Unity

ScriptableObjects/AssetDatabase: Does changing signature leave cruft in binaries?

Discussion in 'Asset Database' started by Nick-Wiggill, Feb 29, 2012.

  1. Nick-Wiggill

    Nick-Wiggill

    Joined:
    Jan 31, 2010
    Posts:
    46
    Let's say you have a custom class that extends ScriptableObject, a pure data object that can thus be serialised just like GameObjects, Components and what have you.

    Now, the class starts out using a small signature, maybe just one or two serialisable public data members.

    You create your .asset with this, and you look at the .asset file: The inspector kindly shows you what you've just created.

    Next, you go back and add an additional public member. Now you've got a different member signature. If you save the script and immediately go back into the IDE and look at your .asset file again, you'll see Unity's smart enough to now show the new data member's presence -- even though that serialised file probably hasn't even been updated yet.

    But this is where things get hazy. Either the IDE in its wisdom has already detected the change to the method signature, and because of that it has gone and updated all .asset binaries that are representations of instances of that class, or else it is just acting as though that .asset file has these new members, when really, it doesn't yet (I strongly suspect this).

    The second part is this. What if, rather than adding certain members, I removed some? Would Unity then automagically go and update all those .asset files, removing the erstwhile data members preemptively? Or is that now-extraneous data just left inside the binary, like so much junk in the average animal's genome?

    (This is setting my teeth on edge because I'm working with this serialised data at the moment and they are ultimately for mobile deployment, so I would like to be reasonably sure that I can persist with the same versions I've been using all along -- or I'm going to have to rebuild the levels from scratch using the "final" (ha, ha) class signature, in order to avoid oversized binaries.)
     
    Last edited: Feb 29, 2012
  2. duck

    duck

    Unity Technologies

    Joined:
    Oct 21, 2008
    Posts:
    358
    What a great question, well-written. I don't know the answer, but I'm going to be looking into this as soon as time permits.
     
  3. George Foot

    George Foot

    Joined:
    Feb 22, 2012
    Posts:
    399
    I'm not 100% sure, but my understanding is that it won't update the files on disk unless you edit the values - and even then, it may not save the updated file for a while. The "Save Project" option on the File menu may or may not help.

    The inspector is not a good indication of which fields are present in the file on disk. It is looking at an instance of your class, constructed with your latest updated code and populated by serializing from the asset file on disk. New fields will just get their default values, and data for old fields will be discarded - there's nowhere to store it.