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. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

LoadLevelAdditiveAsync ... Scene Loading but objects not active?

Discussion in 'Scripting' started by Rob-Hafey, Aug 19, 2014.

  1. Rob-Hafey

    Rob-Hafey

    Joined:
    Jul 24, 2014
    Posts:
    12
    I would like to use Application.LoadLevelAdditiveAsync to load more data into my levels via a scene. My scene consists of simply a GameObject hierarchy. After the call is finished I see my GameObject show up in the Hierarchy but it is disabled/inactive so I can't get a reference to it to be able to use the data.

    This topic is a well beaten horse but I still can't find an answer to my question. Below is my latest iteration after reading the forums. I tried many different things, listed below is my latest iteration.

    Code (CSharp):
    1.     public IEnumerator LoadCubeGenScene( string name )
    2.     {
    3.         // save scene load name
    4.         loadName = name;
    5.         // do sync loading
    6.         op = Application.LoadLevelAdditiveAsync(name);
    7.         op.allowSceneActivation = false;
    8.      
    9.         while ( op.progress < 0.89f ) {
    10.             UnityEngine.Debug.LogError ("op.progress=" + op.progress);
    11.         }
    12.  
    13.         op.allowSceneActivation = true;
    14.         yield return op;
    15.  
    16.         GameObject go = GameObject.Find (loadName);
    17.        // go is always NULL and my GameObject is always inactive?
    18.     }
    19.  
     
  2. image28

    image28

    Joined:
    Jul 17, 2013
    Posts:
    457
    Not quite sure but what happens if you remove the
    Code (csharp):
    1.   op.allowSceneActivation = false;
    and =true lines of code....
     
  3. Rob-Hafey

    Rob-Hafey

    Joined:
    Jul 24, 2014
    Posts:
    12
    Same thing. I have tried probably every combination of flag setting, waiting etc, except of course the one which will make this load work and be active :) It could be I am missing something entirely, but I can't understand the purpose of a disabled GameObject sitting in my hierarchy after this load.

    I am starting to wonder if maybe my scene that I am trying to load is disabled somehow? When I look at the scene it is active.
     
  4. Rob-Hafey

    Rob-Hafey

    Joined:
    Jul 24, 2014
    Posts:
    12
    Last night I wrote some code to "Find" the disabled GameObject which gave me a reference. But when I did go.SetActive(true) my object didn't activate. Does this mean it is really not loaded? Getting frustrated...
     
  5. Rob-Hafey

    Rob-Hafey

    Joined:
    Jul 24, 2014
    Posts:
    12
    Now playing with the scene that I am loading to try to figure out why my prefab won't Activate. I added a "SceneRoot" GameObject to the hierarchy and then added my prefab as a child. After load using LoadLevelAdditveAsync the SceneRoot was active but my prefab was still inactive and I was unable to activate it via SetActive. I can find the prefab and the script just fine but can't SetActive or enable the script. I also can manually activate the prefab by clicking the enable toggle. At that point the prefab loads fine.

    Am I missing something?
     
  6. Rob-Hafey

    Rob-Hafey

    Joined:
    Jul 24, 2014
    Posts:
    12
    Ok, finally figured it out. I had been setting one of the main GameObjects to InActive on startup. My bad, but problem solved!