Search Unity

Addressables AssetReference.SubObjectName is NULL

Discussion in 'Addressables' started by OdIUm, May 23, 2022.

  1. OdIUm

    OdIUm

    Joined:
    Mar 6, 2017
    Posts:
    18
    Hello!

    I decided to borrow a couple of tricks from Unity Open Project.
    When trying to implement a system for loading levels through ScriptableObjects with using Addressables ran into a problem.

    I have:
    1. SO object with Scene Data:
    Code (CSharp):
    1. public class SceneBaseScriptableObject : ScriptableObject
    2.     {
    3.         public AssetReference sceneReference = default;
    4.     }
    2. SceneLoader, that get Scene Data throw the Event Chanel (like in Unity Open Project).

    Rising event to load scene:
    Code (CSharp):
    1. private void RaiseEventInitialScenesLoading(AsyncOperationHandle<LoadEventChannelScriptableObjects> obj)
    2.         {
    3.             this.debugger.Log("Load Event Chanel asset loaded!");
    4.  
    5.             LoadEventChannelScriptableObjects sceneLoadEventSO = (LoadEventChannelScriptableObjects)this.sceneLoadEvent.Asset;
    6.             sceneLoadEventSO.RaiseEvent(this.initialScenes);
    7.  
    8.             this.debugger.Log("Initial Scenes Load Event Raised!");
    9.         }
    Scene Loader:
    Code (CSharp):
    1. private void LoadScenes(SceneBaseScriptableObject[] scenesLoadList, bool showLoadingScreen)
    2.         {
    3.             this.debugger.Log("Scenes (" + this.debugger.SetTextColor(scenesLoadList.Length, this.debugger.BLUE) + ") loading started!");
    4.  
    5.             AddOpenedScenesToUnloadList();
    6.  
    7.             this.activeScene = scenesLoadList[0];
    8.  
    9.             for (int i = 0; i < scenesLoadList.Length; ++i)
    10.             {
    11.                 String currentSceneName = scenesLoadList[i].sceneReference.SubObjectName;
    12.  
    13.                 if (!IsSceneLoaded(currentSceneName))
    14.                 {
    15.                     this.scenesLoadListAsyncOperations.Add(SceneManager.LoadSceneAsync(currentSceneName, LoadSceneMode.Additive));
    16.                 }
    17.             }
    18.  
    19.             this.scenesLoadListAsyncOperations[0].completed += SetActiveScene;
    20.  
    21.             UnloadScenes();
    22.         }
    23.  
    24. private void AddOpenedScenesToUnloadList()
    25.         {
    26.             for (int iScene = 0; iScene < SceneManager.sceneCount; ++iScene)
    27.             {
    28.                 Scene scene = SceneManager.GetSceneAt(iScene);
    29.                 bool isPersistentScene = false;
    30.  
    31.                 for (int iPersistentScene = 0; iPersistentScene < this.persistentScenes.Length; iPersistentScene++)
    32.                 {
    33.                     if (scene.name == this.persistentScenes[iPersistentScene].sceneReference.SubObjectName)
    34.                         isPersistentScene = true;
    35.                 }
    36.  
    37.                 if (!isPersistentScene)
    38.                 {
    39.                     this.debugger.Log("Scene '" + this.debugger.SetTextColor(scene.name, this.debugger.GREEN) + "' added to unload!");
    40.                     this.scenesUnloadList.Add(scene);
    41.                 }
    42.             }
    43.         }
    44.  
    45. private void UnloadScenes()
    46.         {
    47.             if ((this.scenesUnloadList == null) || (this.scenesUnloadList.Count == 0)) return;
    48.  
    49.             this.debugger.Log("Scenes(" + this.debugger.SetTextColor(this.scenesUnloadList.Count, this.debugger.BLUE) + ") unloading started!");
    50.  
    51.             for (int iScene = 0; iScene < this.scenesUnloadList.Count; ++iScene)
    52.             {
    53.                 SceneManager.UnloadSceneAsync(this.scenesUnloadList[iScene]);
    54.                 this.debugger.Log(this.scenesUnloadList[iScene].name + " unload started!");
    55.             }
    56.  
    57.             this.scenesUnloadList.Clear();
    58.         }
    The problems begins in "AddOpenedScenesToUnloadList" in
    if (scene.name == this.persistentScenes[iPersistentScene].sceneReference.SubObjectName)

    SubObjectName is null. So it cant compare it with scene names.
    I cant find anything in googl about this issue. Why SubObjectName can be null?