Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

[bug] Different bundle hash in clean project and subsequent builds (EventSystem ExecutionOrder bug)

Discussion in 'Addressables' started by nik_d, Feb 18, 2020.

  1. nik_d

    nik_d

    Joined:
    Apr 27, 2018
    Posts:
    66
    I've reported it as Editor's bug (1220916), but it affects bundles building with included EventSystem, so repeating it here.
    EventSystem's ExecutionOrder is wrong (0 instead of -1000) when opening project without Library/
    *It also affects to results of building the player and bundles (bundle's hash depends on ExecutionOrder written).*

    == Steps to reproduce
    1. Open clean project Bug-EventSystem-ExecutionOrder-2018 (without Library/ in its folder) in Unity 2018.4.*
    2. Error message in console: "!!! ERROR: EventSystem (MonoScript) execution order: 0 (current) != -1000 (required) !!!"
    3. Close Unity and open project again.
    5. Message: "EventSystem (MonoScript) execution order: -1000 - OK"
    --
    *. You can reproduce by opening project after removing Library/ folder again.
    **. You can repeate checking in editor via menu command: [TEST]->Check EventSystem Exection Order

    Reproduced in 2018.4.16f1 and .2f1 (mac/linux/windows) and bug seems to be old (https://forum.unity.com/threads/eventsystem-script-execution-order-changed-in-2018-3-0b11.588364/)
    It isn't reproduced in 2019.3.0f6 (with asset pipeline v2).

    Workaround:
    Preliminary Unity opening (e.g. with -quit) when building bundles in clean project.
     

    Attached Files:

  2. davidla_unity

    davidla_unity

    Unity Technologies

    Joined:
    Nov 17, 2016
    Posts:
    762
    This is likely an issue with determinism on the engine side. I checked on case 1220916 and it doesn't look like it's been assigned to a team yet. Unfortunately if it is an engine side issue with the Event System there won't be anything Addressables can do in the interim while that's getting fixed.
     
  3. nik_d

    nik_d

    Joined:
    Apr 27, 2018
    Posts:
    66
    Unfortunately yes - it's the engine bug.
    I just want to warn people until it's not fixed:
    Don't build bundles immediately after clean checkout! (e.g. on build-agents)
    First - open project and close it and only after that - execute the build process.
     
  4. nik_d

    nik_d

    Joined:
    Apr 27, 2018
    Posts:
    66
    Workaround without preliminary project opening - fix EventSystem's execution order via InitializeOnLoad:

    Code (CSharp):
    1. #if !UNITY_2019_3_OR_NEWER //already fixed
    2. using System.Linq;
    3. using UnityEditor;
    4. using UnityEngine;
    5.  
    6. /// <summary>
    7. /// Workaround for incorrect EventSystem execution order opening project and building player/bundles without Library in gui/batchmode (1220916)
    8. ///     https://forum.unity.com/threads/bug-different-bundle-hash-in-clean-project-and-subsequent-builds-eventsystem-executionorder-bug.830892/
    9. /// </summary>
    10. [InitializeOnLoad]
    11. public static class FixEventSystemExecutionOrder
    12. {
    13.     static FixEventSystemExecutionOrder() => EnsureMonoScriptOrder("EventSystem", -1000);
    14.  
    15.     private static void EnsureMonoScriptOrder(string scriptName = null, int requiredOrder = 0)
    16.     {
    17.         var scripts = MonoImporter.GetAllRuntimeMonoScripts().Where(x => x.name == scriptName);
    18.         foreach (var script in scripts) {
    19.             var order = MonoImporter.GetExecutionOrder(script);
    20.             if (order == requiredOrder) continue;
    21.             Debug.LogWarning($"Fixing {script.name} [{script.GetInstanceID()}] execution order [{order} (current) != {requiredOrder} (required)]");
    22.             MonoImporter.SetExecutionOrder(script, requiredOrder);
    23.         }
    24.     }
    25. }
    26. #endif
    27.