- Home /
Question by
klausette · Mar 23, 2018 at 11:34 AM ·
scenescene-loadingscene-switchingscene-change
Using parameters of activeSceneChanged?
I was trying to use SceneManager.activeSceneChanged to store the buildIndex of the current and previous scene, using the information about it I found in another question (since the documentation is incomplete) like this:
void Awake () {
DontDestroyOnLoad(this);
SceneManager.activeSceneChanged += MyMethod;
}
void MyMethod(Scene previousScene, Scene newScene)
{
previousSceneIndex = previousScene.buildIndex;
currentSceneIndex = newScene.buildIndex;
}
the currentSceneIndex is always correct and updates with every scene change, but the value for previousSceneIndex starts with -1 and stays that way.
I solved my issue by just ignoring the parameters and adjusting my values like so:
previousSceneIndex = currentSceneIndex;
currentSceneIndex = SceneManager.GetActiveScene ().buildIndex;
but I still would like to know why the other way didn't work, or what the correct use of activeSceneChanged looks like. Is that first parameter not meant to be accessed?
Comment
Your answer
![](https://koobas.hobune.stream/wayback/20220612155212im_/https://answers.unity.com/themes/thub/images/avi.jpg)