RPG Battle Transition

Can anyone tell me how to swap scenes like in an RPG when a battle take place, and reload the previous screen in the same location?

Basically, how do I reload a previous level in the same position as before after swapping to the battle scene?

You need to keep track of the game state and restore the game objects when returning to the previous scene (referring to scene as level). This can become complicated depending the scope of your game. As far as I know, Unity has no way to automatically store the state of a level so it becomes easily reloaded at a later point in time.

You'll have to either

  • Use third party libraries that deal with this problem and use them. Search for it. I don't know any.
  • Write custom code that allow you to restore the state before you went into battle.
  • Find another approach to your battle system.

Another approach would be to have a different place within your scene where battle takes place. Briefly disable the characters in the "main world" while you're in the battle. This might be easier for you to implement. In the end you'll have to make the decision which would fit your game best.

My solution was to make 2 scene, one for the map and the other for the battle. At the loading of the game we spawn both. Each one have one have their own camera.

I did a Battle Manager, when I do the collision I call this and SetRender(true) the battle/camera and vice-versa.

I also did a SetPreference (with int since bool doenst really work) which save if I’m in battle or not. Now in all my overworld script there’s a condition if the Battle is on or not, if yes, nothing work.

//To set my battle

InBatteBool = 1;
InBatteBool); PlayerPrefs.Save();

//To test if the battle is on

if (PlayerPrefs.GetInt
(“InBatteBool”) == 0){}

I don’t know if its clear, it’s my first time haha, don’t hesitate if you have more question!