Search Unity

  1. Improved Prefab workflow (includes Nested Prefabs!), 2D isometric Tilemap and more! Get the 2018.3 Beta now.
    Dismiss Notice
  2. The Unity Pro & Visual Studio Professional Bundle gives you the tools you need to develop faster & collaborate more efficiently. Learn more.
    Dismiss Notice
  3. Improve your Unity skills with a certified instructor in a private, interactive classroom. Watch the overview now.
    Dismiss Notice
  4. Want to see the most recent patch releases? Take a peek at the patch release page.
    Dismiss Notice

[InitializeOnLoad] called during asset import since 2018?

Discussion in 'Extensions & OnGUI' started by Ludiq, Jul 12, 2018.

  1. Ludiq

    Ludiq

    Joined:
    Mar 6, 2015
    Posts:
    449
    I'm investigating a lot of different user reported issues for my plugin Bolt that seem to happen during import and appear to start after Unity 2018.x.

    I do my initialization code uising [InitializeOnLoad] attributes. From my understanding, this attribute calls static type initializers on assembly reload, that is:
    • When the editor starts
    • When entering play mode
    • When the project recompiles
    • After an import of new DLLs
    I think all of my recent issues are coming from that last item. From the symptoms, it seems that importing multiple DLLs causes multiple assembly reloads after each DLL instead of a single assembly reload at the end.

    This is a breaking change for my plugin (and I'm guessing many others!) because I can't guarantee that the my initialization code will work unless all assemblies are properly loaded.

    So my questions are:
    • Was this change in the behaviour of assembly reload documented anywhere?
    • Is there a way of detecting that the Unity editor is currently importing assets?
    If I could answer that second one, I could just skip initialization during asset import and wait for an actual full reload at the end.
     
  2. PsyKaw

    PsyKaw

    Joined:
    Aug 16, 2012
    Posts:
    88
  3. Ludiq

    Ludiq

    Joined:
    Mar 6, 2015
    Posts:
    449
    Ah! This does seem to do the trick, but it also returns true after all DLLs have been loaded (or when the last DLL is loaded). So if I skip my initialization while isUpdating returns true, it won't initialize after a recompile or an import. :/
     
  4. Ludiq

    Ludiq

    Joined:
    Mar 6, 2015
    Posts:
    449
    I take that back. EditorApplication.isUpdating sometimes returns false during asset import when opening the project, so it's entirely unreliable for me at the moment.

    Was there any change in the import/assembly load behaviour since 2018? A lot of my users are reporting issues that seem to stem from there.