Dictionary of string and serialized objects are wiped at run

Issue #430 open
Andreas Podgurski
created an issue

Using Unity 2017.4.9f1 and starting with Odin 2.0, my dictionaries of strings and SerializedScriptableObjects are wiped. If I fill them again and hit play, they are set back to null again. This is a real bummer, as it not only breaks my app, it flushed a significant amount of data.

I don't get any reports from the serializer, enabling error logging and exception throwing. All entries can be edited without any problems, but it seems, nothing is serialized in the end. The serialization debugger shows correct values, the dictionary should be serialized by Odin. Leaving Unity and reloading the project wipes the values as well.

If the dictionary is used unitialized, the dictionary itself is null after run, if there is an initializer, the dictionary is simply empty after run. Enabling/disabling the GameObject has no effect in this case.

Both, the ScriptableObject as well as the dictionary are scanned correctly by the AOT processor, although the false behaviour is in the editor already. No need to run it on the device.

My datatypes are:

public Dictionary<string, Dashboard> EngineDashboards = new Dictionary<String, Dashboard>();

[CreateAssetMenu(fileName = "Dashboard.asset", menuName = "Editor/Dashboard", order = 960)]
public class Dashboard : SerializedScriptableObject {
    public Dictionary<EUnitSystem, Sprite> RPMBackground;
    public Sprite EngineSprite;
    public int RPMGaugeMax;
}

Comments (17)

  1. Tor Esa Vestergaard

    As you might have noticed, Bjarke also replied on this issue, without seeing that I had already assigned it to myself. His message was relevant, though, so here's the important part of it :)

    When did the problem start? Did you update Odin, or did you downgrade or upgrade to 2017.49f1? Or was everything a fresh import?
    Can you confirm whether it's only dictionaries or everything Odin serialized which resets when entering playmode?
    What .Net backend and API compatibility is specified in player your settings?
    And what's your build-target? Does changing built-target changes things?
    Just tried it out in 2017.4.8f1 but will download 9f1 and see if that changes soon. If you have a project which reproduces the problem that would be extremely helpful. Or any more information about what's unique about your setup.

  2. Andreas Podgurski reporter

    I encountered the problem today, after I updated to 2.0 during the week when we both inspected the other issue, which was caused by disabled objects. I discovered this within the editor, as there is a default fallback, so I can't say, if it came with the update to 2.0.3.0 or with the 2.0.4.0 version with your last hot fix. The framework is still the old one, as I sadly can't use the 4.5 framework due to a closed source dependency. Build target at the moment is Android, content of the dictionary is gone on Windows as well on MacOS, where 2017.4.11f1 runs, changing the target doesn't fix it, the data is lost everytime I hit play.

    The problem is very specific to references of SerializedScriptableObjects only. All other dictionaries seem to work fine after your fix.

    The assets are stored within Resources in an own data directory, if that can be of any help (Resources/Data).

    Sadly, I can't send you the whole project, as it is for a customer and requires a non trivial setup to be able to run within the editor at all.

  3. Andreas Podgurski reporter

    Update: I just replicated the Dashboard class and an asset in a private prototype project, running under Unity 2018.3.0b1 and got the same result. I will try to create a standalone example now.
    Update2: Strange, got it reproduced in my private project only once, now there and in the sample it works. An update to 2.0.5.0 made no difference for the real project on the other hand.

    Any idea how we can examine this further? Any additional loggings to enable or such?

  4. Tor Esa Vestergaard

    It seems very mysterious if you can't make a reproduction project. Is it not possible to extract a subset of your project with everything about the object intact, perhaps?

    I can at least corroborate with Bjarke that this doesn't seem to reproduce for me either, which does make this a lot trickier - without reproduction steps, there's not much we can do. As for extra logging, it's a big difficult if it already logs no errors or anything of the sort when you enable full logging of warnings and errors. As soon as anything goes even slightly wrong or not as anticipated, a warning is logged, and if no warnings are logged at all, it seems more likely that the asset's data is so corrupted that the serialization system never even manages to trigger properly in the first place.

    If you add more Odin-serialized members to the asset with the non-working dictionary, do those members work fine?

    Also, if you could send me an example of a saved asset file that contains the non-working dictionary, I can have a look at the serialized data for it, and maybe that will shed some light on matters.

  5. Andreas Podgurski reporter

    I will see what I can do - sending the asset itself won't be a problem, I can send the cs of the corresponding class as well. Maybe I can strip the project down a bit, but the problem is, my successor in the project had, let's say, a favour for singletons.

    In fact, I discovered a similar behaviour now in my personal prototype as well, but it occurs very rare and randomly there. There it is a dictionary between UI buttons and GameObjects (Panels). I'll continue to look into it.

  6. Andreas Podgurski reporter

    Sorry for the long delay, we had to shift focus due to a award submission. To be not blocked by this issue, I hardcoded the dictionary in question, which is not a problem yet, as it contains only three members yet, but it is sure to grow.

    One thing I can say for sure now is, that this is a regression. Due to an expired certificate, I had to rebuild an older version of the app. This version used a version of odin, which was incompatible with Unity 2017.4.x, so I had to upgrade Odin for this build. After this upgrade, this well tested version (Internally used for testing setup variations) showed the very same issue described above, Before, this ran flawlessly. I'll try to send you the source of the class and the associated asset file, maybe that can help. If all fails, I need to check with our customer, if it is ok to send the whole project. You should be able to spot the issue without the need to run the app at all.

    Update: I have prepared a zip with the whole project for you, representing the old version with the updated Odin version, if you are interested in hunting this down. For me, I now went for a workaround, where I created an own asset with the collection in it, as I need it at another place anyway and now I access the collection there, without the issue occuring. Please let me know, if you would like to have a look (Simple to reproduce, no need to dig deep into the project as it is visible in a specific GameObject already in the editor) and how I should send it to you. Please discard the source afterwards, as it contains data, which is considered as confidential by our customer.

  7. Tor Esa Vestergaard

    Thank you for making sure we can take a look at it! That will really help :) You can send the zip to me at tor@sirenix.net, and provide an expiring download link if you want to make sure the file isn't cached anywhere on some email server. I'll make sure to delete the whole thing once I've diagnosed and resolved the issue in question.

  8. Andreas Podgurski reporter

    Sorry, we're hard on the release preparation, but I sent you a wetransfert last night with a simple reproduction description. Hope you can find the issue, because it is very easy to reproduce, although I didn't experienced that behaviour in any other context yet.

  9. Log in to comment