Passing data between scenes

Hi, I’m building a turn-based rpg. Currently I have two scenes set up. One that allows the player to roam the terrain and interact with enemies/npc.
The other scene is for the battle system between the player and enemy.

My question is: How to I save and pass relevant data between scenes ie save the world position of the player, pass the enemy encountered in the world and their stats??

I’ve been looking into using scriptable objects to pass things like stats and such but am struggling coming up with a solution to save world position or pass the specific enemy that was encountered without using something like a singleton logger class?

Any Suggestions?

In my game I pass a data structure that contains all the required information as a parameter in the method that is called to create the combat scene.

There are multiple techniques, ultimately you need to decide which one suits you and your application best.
In short format, you can:

  • use ScriptableObjects to pass data between scenes, since they aren’t tied to the scene
  • you can use DontDestroyOnLoad MonoBehaviours to pass data between scenes
  • you can use static variables

Sooner or later every adventure game like this needs a place where the game progress is stored, kind of a blackboard (and the technique is called just that), where you can store what happened in the game. And what is easily can be serialize out when you save your game progress. It’s like you know, “the player opened the second door so the golden key is used up”-kind of things.
You can use similar stuff to pass data between scenes (since you’re just doing that).

I personally use a global static class with static methods, the dictionaries I use to save data are private and I generate an endless flow of public constants because I don’t want to use strings as keys, I want to be type safe (so I use int) but I also want to use descriptive names.

1 Like