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 (8)

  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 or with the 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 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. Log in to comment