- Home /
Scene Asset Bundle - LoadLevelAdditive and OnLevelWasLoaded
This question has 2 parts.
First :
Is there a way to get the index of a scene loaded from an assetBundle ? At runtime ?
Second :
Is the function OnLevelWasLoaded called when you use the LoadLevelAdditive ?
Now, the reason I want to know this is because i'm using a script which deals with scene changes, it also handles showing and hiding the loading screen when needed. As of now, I was just calling the "Show" method (for the loading screen) before loading a scene, and then, in that scene, I had a script that would "Hide" it from the Start. Let's face it, this isn't... well encapsulated. And it's kind of a pain to need a script in each scene to call the loading screen off.
I recently discovered the OnLevelWasLoaded method, which would actually achieve what I want. Problem is, some of these scenes are bundled. (Not in the project settings), and I have no way of telling which index they are. Hence the First question.
After thinking for a bit, I thought "Well, I don't actually need to know which scene is loaded, I just need to dismiss the screen when a scene is loaded, Any".... well, ends up that's not exactly true. There's some scenes I am loading additively (is that a word ?) And I don't necessarily want the "Hide" function to be called at those times - Well, sure, right now it's not doing much, but it might eventually do. Hence the Second question
If it's not fired, then I could work with this workaround.
Thank you for your time, hope I was clear enough.
EDIT:
I just thought about something, Is it possible to get the name instead of the index ? and then get the index with the name ?
EDIT 2 :
I found part of an answer to that last question Here
Says you can Check names with assetBundle.contains, but not really get the name without knowing it first.
I've been looking for an answer to this with no success. I can't find anything about finding index of a scene, and i can't find anything saying you can't get it either... Am I the only one who sees some utility in this ?
Answer by niall1111 · Sep 17, 2014 at 07:57 PM
This is what you're looking for. :)
http://docs.unity3d.com/ScriptReference/Application-loadedLevelName.html
This definitely adds to the possibilities. Is there a way to find the index of a scene with a name ?
EDIT : Turns out it's simpler than that : http://docs.unity3d.com/ScriptReference/Application-loadedLevel.html
They both basically do the same, returning a different value type. Thanks for the pointer niall.
Your answer
Follow this Question
Related Questions
Application.LoadLevel Strange Problem 2 Answers
Can a script be loaded to a next scene? 3 Answers
Load Scene in AssetBundle and Unload 4 Answers
Multiple Cars not working 1 Answer
Distribute terrain in zones 3 Answers