- Home /
How Reset all !(in scene) without reload scene?!
hello/every body i have 1 question! How Reset all (objects,prefabs,int,information &.....in scene) without reload again scene?! I need help you!Thanks!for answering!
Hi, Haven’t any idea now but why do you need to reset the scene without reloading it?
Answer by Tobychappell · May 23, 2018 at 10:40 PM
Create a class (call it GameobjectInfo) that defines all the things of any object that you would want to reset. Like position, rotation etc. and maybe more custom types including a reference to the gameobject in question.
Have a LevelState class that on awake searches through all gameobjects (not good for performance, probably better if done in editor) and saves their information inside a GameobjectInfo object. You'll want to store this as a dictionary < Gameobject, GameobjectInfo >. Note: i dont see this handling deleted gameobjects, consider just disabling them.
When you want to restore the scene, you get this LevelState class to gather all gameobjects again and Delete any that do not exist as a key in the dictionary, if it does then copy over the information you want to restore.
For your scripts yoi may need to create an Interface where you can pull and push the starting state without having to worry about the type.