+11
Unity Bug

Loading DictionaryAsset / VariablesAsset Failed on Unity 2018

Lazlo Bonin (Lead Developer) 2 years ago updated by Crystalius 2 years ago 27 5 duplicates
There is Unity bug that causes a warning when loading some core Bolt assets in Unity 2018.

We could not reproduce the issue on Unity 2017.4, but Unity QA apparently has been.

The issue has been reported to Unity here and has been confirmed as a Unity bug:

https://fogbugz.unity3d.com/default.asp?1060352_043v4c4efcsmdhv9

The Unity developers are currently working on a fix.

What does it imply?

  • You might lose project settings on editor restart, like your custom type options
  • You might lose application variables on editor restart
My attempts at finding a workaround have been unsuccessful, but I will keep trying especially if Unity does not fix the issue soon.

EDIT August 22: The issue has been confirmed by a Unity engineer and will be fixed in 2018.3. The fix will be backported to 2018.2, but not 2018.1.

EDIT November 27:
 The fix has been backported to Unity 2018.2.18f1.

Bolt Version:
Unity Version:
Platform(s):
Scripting Backend:
.NET Version (API Compatibility Level):

Duplicates 5

Pending Review

Do you have any error or warning pop in the console during the setup wizard or before it appears?

+1

Fix it quickly please

+2
Working on Fix

Working on a fix today!

+2

Spent hours on this one today, but unfortunately it seems like a Unity bug that appeared in 2018.

I submitted an extensive bug report here: https://fogbugz.unity3d.com/default.asp?1060352_043v4c4efcsmdhv9

Pasting here:

Unity 2018 fires additional InitializeOnLoad events that fail to LoadAssetAtPath

1. What happened

I'm investigating an issue for my asset store plugin Bolt reported by all users of Unity 2018+.

The root of the problem is that AssetDatabase.LoadAssetAtPath returns null for valid ScriptableObject in the project.

However, it only returns null when called during the first of two InitializeOnLoad callbacks when opening the project.

Indeed, opening the editor in Unity 2018.x seems to fire InitializeOnLoad at least twice, or sometimes more if managed plugins (DLLs) have to be imported.

With logging, we can see that LoadAssetAtPath only fails during the first InitializeOnLoad, not the second (or subsequent ones).

Back in Unity 2017, InitializeOnLoad only happened once upon opening the editor. (While not the core of this report, it seems that the multiple InitializeOnLoad in 2018 is unnecessary and increases loading times, and could probably be reported as an issue in itself?)

In short, it appears that Unity 2018.x is calling an additional InitializeOnLoad upon opening a project in which the editor is not fully able to load assets yet, which breaks existing codebases.

This causes major issues for my plugin because configuration files which are crucial to the execution have to be loaded from ScriptableObject assets in InitializeOnLoad.

If this can't be resolved for Unity 2018.2, I would greatly appreciate suggestions for workarounds soon, as this prevents my users from using Bolt in Unity 2018.

2. How we can reproduce it using the example you attached

a) Close the editor entirely.
b) Open the attached project in Unity 2018.2.0f2. 
c) Look at the console log (screenshot attached)
d) Notice 2 InitializeOnLoad events are logged, when there should be only one
e) Moreso, in the scope of the first InitializeOnLoad, LoadAssetAtPath returns null, as indicated by my warnings
f) My code is seemingly not at fault here, because the second InitializeOnLoad does not report any error with LoadAssetAtPath.

3. What should happen

Opening the editor should only fire InitializeOnLoad once, and LoadAssetAtPath should not return null during that method call.

I can confirm that the issue is NOT reproducible on Unity 2017.4.3f1.

I have not personally tested with other Unity 2018.x releases, but my users have reported seeing the issue in Unity 2018.1 as well.

Actually this does harm. Some of my favorite units doesn't persist after relaunching Unity, because of ProjectSettings.asset obviously.

So probably there would be harm with ApplicationVariables too.

Tried deleting them, so new, clean ones are generated but it makes problem even worse—Ludiq.Graphs ProjectSettings.asset and Bolt.Core SavedVariables.asset become corrupted.

Looks like it's a bug. Because this happens even on an empty project and there even worse. Posted bug report: https://support.ludiq.io/communities/5/topics/2015-loading-bolt-14-assets-fails-on-a-clean-new-project-20182

Bolt works in 2018.2.1 however it does work with .net4x... 

You will need to keep using 3.5 for now.   

Still will popup as a warning but not a critical(red) error.

+2
Working on Fix

Good news, a Unity engineer answered the bug report and described where the pipeline changed in 2018.1. I'm still unsure how to fix it, but it's a step in the right direction. I'll be seeking additional support from Unity as this appears to be a breaking change in the initialization routine.

This is a high priority issue for me and I'm working to get it fixed ASAP.

+1
Unity Bug

Just heard back from the Unity engineer! The issue is indeed a Unity bug and will be fixed in 2018.3. The fix will also be backported to 2018.2, but not to 2018.1. Therefore, the issue will only remain if you use 2018.1.

Quote from the report:

Hi again

Turns out the issue was a bug that would load your precompiled .dlls along with our Unity .dlls on the first load of assemblies in the editor. LoadAssetAtPath would then fail BECAUSE we hadn't fully initialized Unity before loading your .dlls. This has now been fixed, so it has the same behaviour as in 2017.4. Single InitializeOnLoad call and LoadAssetAtPath works correctly.

The fix will land in 2018.3 and backported to 2018.2, since support for 2018.1 has ended due to our new TECH/LTS release schedule(1) it will not land in 2018.1

Lukasz
+1

Thankz Lazlo! You are a true hero!

Is there any released Unity version that fixes this? After encountered the issue with my settings not saving, I deleted Ludiq and Bolt from my project but I still can't save my settings. Is there something linger with the installation?

In fact, the Unity 2018.3 beta that just released should fix this. I haven't had time to test myself though!

+1

It appears to be working, at least for me in Unity 2018.2.8f1.

The error is still there in 2018.2.8f1 for me.

Unity 2018.2.9 here. Problem seems to still be there. 

I am getting those on mine and on even new empty project:

Some settings disappears, like in Configuration and Favorites

+3

The fix landed in 2018.3, according to the QA person I talked to. If I understand Unity's release cycle correctly, they only backport fixes to prior versions (in this case 2018.2.x) when the next version becomes stable; so I'm expecting 2018.2 to get this fix when 2018.3 gets out of beta.

Thanks Lazlo, Appreciating the hard work!

Still getting same warnings and for some reason, even the "Favorites" in fuzzy selection disappeared. No such option anymore.

2018.2.15f1

Also, can't see fix in 2018.3 beta yet https://unity3d.com/unity/roadmap

+1

So there's been a back & forth between Unity QA and us, they say they fixed it in 2018.3.0b1 and can't replicate it anymore. Can you try updating to 2018.3b and see if it fixes it?

If you can still replicate it I'll update my bug report with them to let them know. I haven't had time to give it another look recently with Bolt 2 alphas but it's still on my radar.

+2
Good news! Update from Unity QA: The fix has been backported to Unity 2018.2.18f1!
Hi,

Thank you for reporting the issue.

We have fixed this bug in Unity version 2018.2.18f1 . 

If you are still able to reproduce this issue on the latest version of Unity, please respond to this email.

We highly appreciate your contribution. If you have any questions, feel free to contact us.

Regards,
Ilya
Unity QA Team
+1
Great but 2.18 is still not there yet. Will update after I check it :)
+1

Installed 2.18 and everything looks fine now. Great! :)