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.
public IEnumerator LoadCubeGenScene( string name )
{
// save scene load name
loadName = name;
// do sync loading
op = Application.LoadLevelAdditiveAsync(name);
op.allowSceneActivation = false;
while ( op.progress < 0.89f ) {
UnityEngine.Debug.LogError ("op.progress=" + op.progress);
}
op.allowSceneActivation = true;
yield return op;
GameObject go = GameObject.Find (loadName);
// go is always NULL and my GameObject is always inactive?
}
Not quite sure but what happens if you remove the op.allowSceneActivation = false;
and =true lines of code…
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.
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…
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?
Ok, finally figured it out. I had been setting one of the main GameObjects to InActive on startup. My bad, but problem solved!