Why not save everything to the game persistence level?

Hi mrstarks510

I need to clarify a few things you said:

I learned save my character stats to
the player controller and not the
player pawn as it will be destroyed
during level transfer and the
controller will likely stick around.
But now I need to save those variables
to game mode as the controller will
not carry over because the controller
needs to change for the battle
mechanics

When changing level, all objects except the game instance will be destroyed and re-created. There are only two ways (in non-networked applications) to transfer data between maps.

  1. The GameInstance remains persistant therefore any data stored within this class will be transferred between levels. However, I would highly recommend NOT overloading this class. I will explain a bit later about the purpose of each class.

  2. Using a save object. Save objects are great for storing the types of data you mentioned. Not only can the data be transferred between levels, but also they can retain this data between application launches. I.e. someone can set the desired resolution and the next application launch can pick up that setting. If you don’t need data to be transferred between launches, you can destroy the slot on the application exit.

When you say “Game Persistence Level” I am assuming you mean the level blueprint for the persistent level.

There are a few reasons NOT to store everything here. It really comes down to understanding Unreals architecture for project setup. Each object has a purpose and we should assign the data we are working with the appropriate object. Here are some reasons:

  1. Player and Game objects will get complicated very quickly in larger projects. Having all logic/data in one place will be a nightmare to maintain. Even more so, there it will be a pain to debug because its harder to track where this data is being set / accessed.

  2. The larger the class / object, the longer it takes to compile and load. It can also have a heavy performance hit if these classes are making calculations they don’t need to.

  3. Scope is important. When you get more experience and perhaps you start looking at the C++ side of things, you will be able to explore “private”. “protected” and “public” scoped data which drastically helps keep these classes organised.

Unreal Engine heavily adapted the Object Orientated Programming paradigms. By setting up classes appropriately you will eventually explore inheritance which is another brilliant way to help structure your projects and share data between classes.

I live by the rule “Objects should look after themselves”. If an object has no need for some data, it shouldn’t know about that data, It’s that simple. Using the built event systems you can really isolate each object and keep track of how your objects are performing, thus making debugging life simpler.

Lastly, I will give a quick break down of the major objects:

Game Instance: Control the rules for the application.

Game Mode: Control the rules for the level and manage controller objects.

Game State: Facebook profile for the Game Mode (networked applications)

Player Controller: Controls all the rules for the user, manage input, and any objects related to the user.

Pawn / Character: Represent controllers in the world (user and AI). Can be generated multiple times during a level.

Player State: Facebook profile for the Player Controller. (networked applications)

Player HUD: Control and manage UI

Persistent Level: Manage world objects and assist in creating relationships.

Bottom line, all this stuff you will pick with experience, when you start working with larger projects you will see the need for separating all data into the appropriate classes. I would highly recommend download projects released by Epic such as Robo Recall, so you can get a sense of how each of these objects should be utilized.

I hope this helps.

Alex

1 Like

I’ve reached my next stage of beginners development, saving variables across levels game modes and such. But there is one question I cannot find the answer to. Why not save everything to the game persistence level?

I learned save my character stats to the player controller and not the player pawn as it will be destroyed during level transfer and the controller will likely stick around. But now I need to save those variables to game mode as the controller will not carry over because the controller needs to change for the battle mechanics. Then, still learning, the battle mechanics should be a separate game mode than the base world format and will also be lost when game modes are switched. I read up on game state and discovered it much like the game mode doesn’t like me. So I arrive at game persistent.

To be fair I know there is a lot of reference getting throughout the experience I described, which doesn’t completely work as of now, but I’m learning. I really really want to understand why? Thank you all advice and knowledge.

Thank you this is very helpful. I will have to do more reading and dig deeper into the UE lessons. Maybe take it a bit slower than I have. I’ve yet to download one of the projects like Robo Recall because didn’t know where to start with those projects. I know what I want to accomplish, but I run into this sort of issue when I don’t know what I’m looking at or looking for.

Like when I learned how to make player health. It went from integer to float because the use of the percent bar. But how to get my health numbers to always be whole? When I did find a work around solution through one of the UE live training sessions I saw a better way staring at me. Move the numbers to the left of the decimal. It was a sad moment for myself. Then later I hear that that way will make things complicated later on when equations are involved in calculating damage. I’m far from equations, but doesn’t It make sense to learn things or the fundamentals correctly? The first time? Rather than having to unlearn an relearn every step of the way because you taught yourself the “wrong” way to do something?

It’s possible I’m overthinking it. Or I’m just too hard on myself. I guess now that I’m several steps ahead from where I started I can better understand what I’m looking at within projects like Robo Recall. Thanks for your help. And like you said the learning experience and how I apply it, at least for now, is going to be my best guide to make sure I’m on the right track.

Hi mrstarks510

I am glad you found my answer helpful.

Everyone starts off in the same boat. Trust me I cringe when I look at the first few projects I created in Unreal and the way I handled the information. It takes time to learn and understand.

Also, remember that different types of projects may require different setups. So just because one project or tutorial shows you how to do something one way, doesn’t mean it would be appropriate for every implmentation. Once you’ve got more experience and a better understanding of what each of these classes does and what they are used for, you will be able to informed decisions to come up with your own implementations when setting up your projects.

One final piece of advice, I would move away from project templates asap. Project templates (like the first person shooter), often handle a lot of the setup for you, such as assigning classes, handling pawn possession, and setting input modes. Creating your own projects from scratch and recreating the logic inside these templates is another great way to gain a better understanding.

Good luck!
Alex