- Home /
Regarding setActive
Hi, I have an issue that I can't find a solution for it, I have two panels on top of each other and depends on a button press I do setActive(true) and the other is false the problem is when I go to different scene and go back to this scene the change isn't saved and I go back to what it was originially any helpful tips please?
Answer by MrKagouris · Nov 12, 2016 at 07:37 AM
You can use this to save data across sessions (and thus scenes). It only saves ints, floats and strings though, so you might need to get a little creative to make it save and load a GameObject's Active state.
I followed your advice to be creative and you were right it wasnt related to PlayerPrefs I just need some static flags to hold the state of it and a test condition for these flags to set the corresponding panel to be active
Answer by FiveFingerStudios · Nov 12, 2016 at 09:22 AM
Whenever you load a scene, it loads at how you left it when you last saved. That means if you change something and don't save the scene, it will now save the change.
You would need to save the setActive state to disk, or a singleton that remains alive between scenes.
If you want to do a permanent save (between robots of your computer) you need to save to disk. One easy way is to you "PlayerPerfs" to save and load the state.
A singleton object can store between scenes but requires a little bit more programming knowledge.
Answer by nomischen · Nov 12, 2016 at 07:56 AM
To save data between Scenes, its easy to use
PlayerPrefs.SetInt("VariableName", VariableValue);
int HealthorWhatever = PlayerPrefs.GetInt("VariableName");
That data also saves when you exit, Its useful for savegame. But if you're saying the scene isn't saved, save the scene with Ctrl+S
Answer by James-Laker · Nov 12, 2016 at 07:39 AM
You can use the PlayerPrefs for that. You should try and keep it small from what I remember.
Your answer
![](https://koobas.hobune.stream/wayback/20220612100517im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Calling an Audio Source on one game object from a script on another game object..? 1 Answer
How Can I Copy My Gameobject To Other Scene How Can I Copy Gameobject to different scene 1 Answer
List objects in a scene file 0 Answers
Levels: scenes or GameObjects? 3 Answers
Best workflow for DontDestroyOnLoad method regarding Unity Editor? 1 Answer