SceneManager.LoadScene()

So, I almost got the challenge for this, but couldnt figure out how to attach the explosion GameObject to deathFX, so I played the video until I saw ‘[SerializeField] GameObject deathFX;’ and had an ‘aha!’ moment.

Anyway, I ended up doing the scene reload slightly differently and went with the below (which I also used in Project Boost):-

SceneManager.LoadScene(SceneManager.GetActiveScene().buildIndex);

Is there a reason for specifying the scene number (as in the lecture video) over using GetActiveScene().buildIndex as I have been doing? It makes sense to me to get the script to figure out which scene it is, rather than telling it which one to reload, but perhaps I’m missing something?

1 Like

Hi Gareth,

It’s probably just been done for simplicity in this section/lecture, however, any get or find is going to use some resources, when you use GetActiveScene you are requesting an entire scene, and thus everything in it. In Argon Assualt I doubt this would be much of an issue, but if you could imagine an enormous scene, with many many GameObjects and much more complexity - you’d be getting all of this, just in order to access an int representation of the scene to then use to load the next scene. At that point, I would suggest it would be overkill and not cost effective.

If you have, for example, a persistent GameManager/Controller in your game, you could keep track of the scene index within this, the overhead of then accessing/using it would be tiny.

Hope this is of use :slight_smile:

Ah, that makes sense. Thanks for the explanation :+1:

1 Like

No worries :slight_smile:

Privacy & Terms