Preferred Types get wiped when there's lots of code changes

NodeCanvas Forums Support Preferred Types get wiped when there's lots of code changes

Tagged: 

Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • #15618
    tenpn
    Participant

    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.

    Is there a better fix than this? Has anyone else encountered this issue? Any potential pitfalls that I should be aware of?

    #15630
    Gavalakis
    Keymaster

    Hello there and thank you for the thorough post.

    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.

    Regarding ReflectionTools FlushMem, I think it would be better to add the following attribute on FlushMem instead:

    Thank you! 🙂

    Join us on Discord: https://discord.gg/97q2Rjh

Viewing 2 posts - 1 through 2 (of 2 total)
  • You must be logged in to reply to this topic.