Hello, unfortunately I didn’t find anything about my problem in the forum:
Is there a way to create a scene based memory?
Let’s say I have 4 scenes / levels.
In scene / level 1 there are 2 opponents, if I kill 1 opponent I spawn in scene / level 2. If I don’t kill an opponent, I spawn in scene / level 3.
From scene / level 2 and 3 I come to scene / level 4, where however I am confronted with my actions in the scenes before. (A kind of moral system)
Does anyone have any idea how to do this?
Data that should be kept when a scene is unloaded must be kept outside of that scene. You can do this by
- using static fields,
- using DontDestroyOnLoad on a GameObject to move it to a permanently loaded scene or
- storing the data in an asset, like a ScriptableObject.
I’d recommend staying away from DontDestroyOnLoad as long as you don’t need a component running through a scene change (like, for example, a music player). Both static fields and ScriptableObjects can work fine. ScriptableObjects would require a bit of initial coding to get a proper data framework going, but it has been done before, so you can look out for existing frameworks like mine (self-advertisement gogo): Soda - ScriptableObject Dependency Architecture | Integration | Unity Asset Store
But static variables and other frameworks can work well too