Search Unity

  1. Unity 2019.1 beta is now available.
    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. We're looking for insight from anyone who has experience with game testing to help us better Unity. Take our survey here. If chosen to participate you'll be entered into a sweepstake to win an Amazon gift card.
    Dismiss Notice
  4. On February 28th the Feedback website will shut down and be redirected to the Unity forums. See the full post for more information.
    Dismiss Notice
  5. Want to provide direct feedback to the Unity team? Join the Unity Advisory Panel.
    Dismiss Notice
  6. Unity 2018.3 is now released.
    Dismiss Notice
  7. Improve your Unity skills with a certified instructor in a private, interactive classroom. Watch the overview now.
    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:
    503
    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:
    93
  3. Ludiq

    Ludiq

    Joined:
    Mar 6, 2015
    Posts:
    503
    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:
    503
    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.