Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

How would you guys handle battle scene transitions in a RPG?

Discussion in 'Scripting' started by Yukken, Mar 1, 2018.

  1. Yukken

    Yukken

    Joined:
    Jul 12, 2015
    Posts:
    89
    I've been slowly working towards my goal of making a spiritual successor to grandia. I'm almost done with the battle system and I need to integrate it with the over world exploration system. The player will encounter random battles as he walks around the over world.

    Currently, over world exploration and and the battle system are on different scenes and I need to transfer data between them. For example, I need to know which party members the player has and which enemies he has encountered so that I can load them into the battle scene. the question is- How do I transfer data like this between scenes.

    One solution is to serialize the data and load it in the battle scene but I'm not sure if that's the best approach here. I also haven't delved into serialization too deeply. I have been leaving it for later until I implement a save system. So I would really appreciate any pointers on solving this problem.
     
  2. Lurking-Ninja

    Lurking-Ninja

    Joined:
    Jan 20, 2015
    Posts:
    9,905
    There are many ways to do it:
    - Create a game object with a script on it with DontDestroyOnLoad https://docs.unity3d.com/ScriptReference/Object.DontDestroyOnLoad.html (I don't like the non visual gameobjects in the scene, personally), and store the data in that script.
    - Create a static class with static data members, dump the data there (it acts like global variables, so be careful with this)
    - Create a scriptableobject with the structure and fill it up with your data and you can attach it to scripts on both scenes, so data will be carried over on switch (but will be destroyed when you quit the application/game) - personally I like this the most
     
  3. Yukken

    Yukken

    Joined:
    Jul 12, 2015
    Posts:
    89
    I thought you couldn't modify scriptable objects on runtime.

    The other two approaches seem like they'd go well with a singleton/game manager approach. I'll probably need a game manager anyway to keep track of what state the game is in (menu/ overworld and so on) so I'll give those a shot.
     
  4. Lurking-Ninja

    Lurking-Ninja

    Joined:
    Jan 20, 2015
    Posts:
    9,905
    On the contrary, you can modify it, but it won't persist. (Which means it is not too useful for saving game state)
    Even game architecture can be written with scriptable objects. Which I'm doing as well.

    And you will have to save your active game state as well (at least into memory) if you're planning scene change for battle. Because I guess after the battle you will want to return into the state where you left, minus the various wounds and losses, I guess, but the world state should remain the same.

    So maybe it would be a good idea to plan that serialization system sooner. :)
     
  5. Yukken

    Yukken

    Joined:
    Jul 12, 2015
    Posts:
    89
    That sounds pretty useful actually. I could use that to let the player retry a battle if he happens to lose. I'll try implementing it this way and see if it works out for me.
     
  6. Yukken

    Yukken

    Joined:
    Jul 12, 2015
    Posts:
    89
    I've been poking around a bit and somebody told me that I could simply use two cameras.That seems like the easiest solution so far.
     
  7. Lurking-Ninja

    Lurking-Ninja

    Joined:
    Jan 20, 2015
    Posts:
    9,905
    Well, if everything fits in the memory, you can even load scene additive and then delete the content when you finish the battle, this way you can have multiple battle scenes.
     
  8. Saxgu

    Saxgu

    Joined:
    Jan 30, 2017
    Posts:
    2
    I'm curious to know which option worked best for him after 3 years. I'm beginning to use unity and this is a question I have for a game I have in mind
     
  9. Yukken

    Yukken

    Joined:
    Jul 12, 2015
    Posts:
    89
    That's one hell of a necro.
    Like all beginner RPG projects, this was abandoned. So I actually ended up using none of the approaches.
    However, I can answer from my from my current experience, Two problems here: the party data must survive cross scene. That calls either for a singleton or a Scriptable object.
    Then there is the question of the battle scene area. You can definitely get away with using two camera with the battle scene being part of a normal scene. However, I'd recommend making the battle scene an actual separate scene that you load additively. Because you might want the same battle scene across different areas, making them a separate scene will make it less redundant.
    With the new prefab system, you could also make the battle scene a prefab. However, prefab references will eat up memory. Scenes do not. And scenes can be loaded asynchronously. You can do that with prefabs by making them addressable But that's another rabbit hole.

    TL;DR separate scenes loaded additively.
     
    Saxgu likes this.
  10. Saxgu

    Saxgu

    Joined:
    Jan 30, 2017
    Posts:
    2

    Thanks... iirc additive load for scenes means that it loads on the back ground until it is fully loaded right?
     
  11. Yukken

    Yukken

    Joined:
    Jul 12, 2015
    Posts:
    89
    Yes.