- Home /
The question is answered, right answer was accepted
Question Regarding Don'tDestroyOnLoad Object
Hi, I want to ask one thing, I have some objects that attached with the script of Don'tDestroyOnLoad scripts so that the objects will brought to other scene... But I want a certain scene to not have that don'tdestroyonload objects, so i have been searching and found the code working but the problem is once I return to that certain scene all the button at there won't work anymore like being stuck or being trampled by invisible panel so i can't touch anything... Here the code for one of my objects
public class CameraCon : MonoBehaviour {
public Transform target;
public float mspeed;
Camera mycam;
private static bool camExists;
public static int menuScreenBuildIndex;
// Use this for initialization
void Start () {
DontDestroyOnLoad (transform.gameObject);
mycam = GetComponent<Camera> ();
if(!camExists)
{
camExists = true;
DontDestroyOnLoad (transform.gameObject);
} else {
Destroy (gameObject);
}
SceneManager.activeSceneChanged += DestroyOnMenuScreen;
}
// Update is called once per frame
void Update () {
if (target){
transform.position = Vector3.Lerp (transform.position, target.position, mspeed) + new Vector3 (0, 0, -10);
}
}
void DestroyOnMenuScreen(Scene oldScene, Scene newScene)
{
if (newScene.buildIndex == menuScreenBuildIndex)
{
Destroy (gameObject);
}
}
}
I hope everyone can give me a solution on how to destroy the objects on certain scene For Example Case : I made an 2D RPG game with some objects that i don't want to destroyonload but I want to destroy it when I return to the main menu from pause and when I back to my game again, I want everything back to normal again like usual... (Probably might include saving or loading system that i still don't understand so much)
Answer by Zetya96 · Dec 04, 2017 at 05:02 PM
Hi!
You can check if something is "between" the cursor and the button. In the editor select the event system from the hierarchy, and in the inspector, you can see what the cursor is pointing at. Its called Pointerenter, i think.
Hi, thanks for the advice... I found the error which is the base input script is gone the second time I return to that scene... Is there a way to make sure the base input script to appear again?
Here the pic... The first one is when I enter for first time, the second one is when I enter the game and return, I was thinking that it probably due to double event system since I have Canvas Object with another event system within the don't destroy on load too...
Hello again, Strange. I think the simplest solution, is to make a prefab of the working event system, and in a loading screen, or in the menu, check if the eventsystem is already created, if no, then just simply instantiate the eventsystem prefab, make it DontDestroyOnload, and then there's always an eventsystem.
Also, check "Force $$anonymous$$odule Active" just to be sure.
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
Distribute terrain in zones 3 Answers
Why do I loose my Animator? 0 Answers
Keeping variables between scenes with scriptable objects? 0 Answers
Multiple EvenetSystems in Scene - only have 1 after searching though 1 Answer