Hi folks, I’ve spent a day or so looking into this issue and think I understand why it’s happening. I have a workaround but you might have better suggestions?
The issue is that the preferred types list sometimes loses all our game’s types. We have a PreferredTypes.typePrefs committed in source control, but sometimes when we sync and reopen unity, it throws all those custom types away.
A great repro is to close unity, delete your Library/ScriptAssemblies folder, and reopen unity. Your preferred types list will now be empty.
What’s happening is that TypePrefs.LoadTypes() is firing while the game’s DLLs are still being compiled. If you look at CurrentDomain.GetAssemblies(), our game DLLs are not there yet. TypePrefs loads the pref file in TryLoadSyncFile, but when it Deserializes to a List<Type>, the unknown types are thrown away. Then it instantly deserialises again to the typePrefs file, so when the game DLLs finally compile, and the type prefs are loaded again, they’re still missing game types.
My workaround was to look in the CurrentDomain.GetAssemblies() list for Assembly-CSharp, and if it’s not there, abort the LoadTypes() operation. I also tried a EditorApplication.isCompiling guard, but this didn’t work by itself. I also ReflectionTools.FlushMem(), just to be sure we’re getting fresh data, but I’m not sure that’s necessary. All together this stops TypePrefs from touching anything until it knows everything is settled.
Indeed; because NodeCanvas is in a different assembly (due to asmdef use), apparently it is loaded before “Assembly-CSharp” and as such LoadTypes is also called before like you explain. I’ve looked a bit into this and your fix is actually fine, however only the following code is really needed.