How do i initialize only once for a scene?

hi guys, i have my level one scene, and it initialize some GUI on screen, and when i head over to level two scene, the GUI stays there, but if i go back to level one scene, it creates another GUI which is like, stacking over the first GUI, how do i get it to only render like once in the whole game? Thanks!

Your object is probably set to “DontDestroyOnLoad”. This means that it will not be destroyed when you change scene. But it does not guarantee that there will only be one. You can check when the object is created if there is another instance of it in the level.

Add this to your GUI script:

void Awake()
    if( GameObject.Find( name ) != null ) {
        Destroy( gameObject );

    // Whatever other stuff you need to do...

This snippet assumes that both scripts are attached to an object of the same name. You could do something more sophisticated if necessary.