- Home /
Multiple Instances of My Current Scene?
Hey all, I've got a slight issue with my project, I'm trying to reset the current scene if my player leaves the camera view-port.
The trouble originally was that when it did refresh, the directional lighting would not come back with it, so I looked that up and it turned out I had to go into the lighting settings and uncheck the 'auto' checkbox and hit "Build", that worked, but since then whenever I test the project out, after I'm finished it will show multiple instances of my current scene sitting in the hierarchy when normally there is none.
This happens even if I don't give the game a chance to even use the reset function. But it won't happen if I comment out the following code from my script, it's very strange.
void OnBecameInvisible()
{
//Application.LoadLevel(Application.loadedLevel);
int scene = SceneManager.GetActiveScene().buildIndex;
SceneManager.LoadScene(scene, LoadSceneMode.Single);
}
I've left in my first method but commented it out in case I need to revert back, but both of these functions do the same thing and both produce the multiple scenes problem.
Also when using that code to reset it, when the player does leave the screen when I'm not in fullscreen mode while in the editor testing it, it doesn't reset the player at all.
Does anyone know the reasons for these problems?
"multiple instances of my current scene sitting in the hierarchy" - Not sure what you mean by this? Your scene object should never appear in the hierarchy. Can you post a screenshot?
Yeah I attached it in a comment above, it's weird because it's never happened to me before, I've never before seen the scene inside of the hierarchy.
I'll attach it again here.
I can't explain why that's occurring, but OnBecameInvisible()
is not that useful a function and doesn't work the way most people think, and I'm wondering if that's related to the problem.
What are you trying to test whether it's visible or not? The player? OnBecameInvisible
will only fire when an object is not rendered by any camera, and when you're playing in the editor, that includes the scene camera. If what you're trying to say is something like "OnPlayerLeftTheScreen", I'd recommend you try another approach, like testing whether the player's transform.position x or y leaves certain bounds, and seeing if that fixes the problem.
Alright thanks, but I want my game to work correctly for all screen dimensions, is there a way to check if it's left a screen no mater how wide or tall it is?
Also I've tried the scene.manager as just hitting the R key to refresh the scene and it still does it.
I'm more inclined to think it's something to do with the lighting setting I had to do in-order to bring the directional lights back after a refresh.
Your answer
Follow this Question
Related Questions
Renderer on object disabled after level reload 1 Answer
Current scene number 2 Answers
How the scene works 1 Answer
My scene won't load! 1 Answer