Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Question SO OnEnable and InitializeOnLoad not triggered after Domain Reload

Discussion in 'Editor & General Support' started by vladimir-fs, Sep 4, 2023.

  1. vladimir-fs

    vladimir-fs

    Joined:
    Nov 28, 2019
    Posts:
    22
    Hey y'all

    I've been working on setting up support for async batchmode builds. There's not a lot of documentation on it that I've been able to find. Just these two threads (thread one and two) but I haven't been able to make this work.

    I'm using a scriptable object with hideFlag set to HideFlags.HideAndDontSave in OnEnable.
    This scriptable object is basically a state machine writing an "Next build step" enum value to its serialized field and reading that post-domain reload to know which step to trigger next.

    The flow I have right now is
    1. Switch platform with EditorUserBuildSettings.SwitchActiveBuildTarget
    2. Wait for domain reload
    3. Set defines with PlayerSettings.SetScriptingDefineSymbolsForGroup
    4. Wait for domain reload
    5. Run build with DoBuildForTarget
    6. Clean up defines
    7. Wait for domain reload
    8. Exit application
    This works perfectly in the editor but when I run it in batchmode both the static constructor (if I use InitializeOnLoad) and OnEnable of the SO are only ever called once.
    1. The static constructor is called only when the project opens
    2. OnEnable is called only when the method passed via -executeMethod creates the SO and starts the build.
    This approach works fine while I'm in the Editor but it never seems to recover from its first domain reload when in batchmode.
    In batchmode I can see in the logs that the domain reload is being triggered once and then Unity just waits because I'm guessing the SO didn't make it and I'm calling batchmode without the -quit option.

    What am I doing wrong here? How do I get my SO to survive a domain reload and keep the build moving?

    EDIT: I'm using Unity 2020.3.48f1 on Windows.
     
    Last edited: Sep 4, 2023
  2. vladimir-fs

    vladimir-fs

    Joined:
    Nov 28, 2019
    Posts:
    22
    Bumping this, still looking for an answer.
     
  3. vladimir-fs

    vladimir-fs

    Joined:
    Nov 28, 2019
    Posts:
    22