Hello everyone
So i am fairly new to Unreal Engine, just like 2 weeks by now.
I built an actor component for a survival system (Thirst, Hunger, Sleep etc.), wrote some decrementing logic, HUD logic and all and attached the component to the player actor.
Now i came across an issue, how to make the data inside the component survive a level transition and, later on, also saving / loading.
However even after much reading i can only come up with two potential solutions:
-
Basically throw the actor component away, make a GameInstance and throw all the variables and logic in there. That is my least preferred option, as this would cause quite an extensive rewrite of a lot of things right now. But i also think it might be better in the long run, especially seeing the saving and loading.
-
A combination of the two. So my idea was to replace all current variables with a struct in the component and also make a “Global” struct in the game instance. The game instance would get updated when necessary (e.g. actual changes happened) and when the player character gets constructed i simply set the saved struct in the players component. I just don’t know about saving/loading but it would be a lot less rewriting code.
I tested option 2 a little and it seems to work. But i am unsure if this is the “correct” way and if it would work fine later down the line.
So my question to everyone here is, what option would you choose? Or do you potentially know a better way even?
Thanks in advance!