- Home /
Function not called after load level
I have a static Manager class, that I'm using to do scene transitions.
On changing scene, I add an object to fade out, then call
Application.LoadLevel(currentTargetLevel);
// Instantiate object here.
Then instantiate a new object to fade back from black to transparent, in the new scene.
However the line immediately after Application.LoadLevel() is executing in the previous scene.
Why is this?
The only method related to loading being finished is to do with asynchronous loading of levels, or GameObjects within the scene.
Answer by aaronov · May 09, 2013 at 11:04 AM
I can't recall but I don't think a static class will persist between level loads unless the GameObject the script is attached to is set to not be destroyed (see below). So I think the object is being destroyed and script execution halted once you call Application.LoadLevel(...).
void Awake() {
DontDestroyOnLoad(transform.gameObject);
}
Your answer
![](https://koobas.hobune.stream/wayback/20220613101858im_/https://answers.unity.com/themes/thub/images/avi.jpg)