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

Is RuntimeInitialization() not with RuntimeInitializeLoadType.BeforeSceneLoad mode a bug?

Discussion in 'Addressables' started by 5argon, Nov 5, 2018.

  1. 5argon

    5argon

    Joined:
    Jun 10, 2013
    Posts:
    1,555
    EDIT : I saw a fix on 0.4.8. Thank you for that.

    Code (CSharp):
    1.         [RuntimeInitializeOnLoadMethod]
    2.         private static void RuntimeInitialization()
    3.         {
    4.             //these need to be referenced in order to prevent stripping on IL2CPP platforms.
    5.             var sap = Application.streamingAssetsPath;
    6.             var pdp = Application.persistentDataPath;
    7.             Debug.LogFormat("Using StreamingAssetsPath {0}.", sap);
    8.             Debug.LogFormat("Using PersistentDataPath {0}.", pdp);
    9.             ResourceManager.ExceptionHandler = (op, ex) => Debug.LogException(ex);
    10.             ResourceManager.OnResolveInternalId = AddressablesRuntimeProperties.EvaluateString;
    11. #if !ADDRESSABLES_DISABLE_AUTO_INITIALIZATION
    12.             Initialize();
    13. #endif
    14.         }
    Currently it is not possible to use Addressables in Awake because initialization logic is in this method.

    Initialize() is depending on ResourceManager.OnResolveInternalId = AddressablesRuntimeProperties.EvaluateString; or else the runtime data path will stays in a bracket syntax.

    In Addressables.LoadAsset there is a branch so that when not initialized, it will call InitializationOperation property to wait on it before chaining to the actual load asset, returning one chained together IAsyncOperation. But this InitializationOperation calls Initialize(), and so we need ResourceManager.OnResolveInternalId registered before this branch can work.

    In other words this initialization-safe Addressables.LoadAsset works only when not in an Awake phase (RuntimeInitialization() already run, so the string resolver is registered) but at the same time the init config file is not finished loading yet.

    From roughly looking just by adding `RuntimeInitializeLoadType.BeforeSceneLoad` to the attribute it would allow me to use Addressables.LoadAsset on Awake, and then it should wait for the initialization correctly. Any reason that it is AfterSceneLoad currently? (And so, after Awake as stated in https://docs.unity3d.com/ScriptReference/RuntimeInitializeOnLoadMethodAttribute.html)
     
    Last edited: Nov 6, 2018
    Dinamytes likes this.
  2. unity_bill

    unity_bill

    Joined:
    Apr 11, 2017
    Posts:
    1,053
    glad the fix worked for you. Also, thanks @5argon for helping so many people on this forum!
     
    5argon likes this.