Cloning actor (state) in turn-based combat game

I’m working on a turn-based combat game (Mix C++/BP).

When a battle kicks off, I want to spawn my fighter into the battle scene. If it wins, it has presumably changed state - used inventory items, stats (represented as a Gameplay ability system UAttributeSet) will have altered. If I win the battle, I have to store these changes, so I figure just let my Game Instance cache a pointer to the fighter. If I lose, I have to restore the state to how it was before the battle.

I’m not sure how I can robustly manage this state. Can I clone the UAttributeSet (including any gameplay effects supplying buffs?) There doesn’t seem to be a way. Can I (deep) clone the entire actor and keep a pointer to it in the Game Instance outside of the visible scene and use that to restore it? That seems very wasteful.

Or something else?

Few hints:

  • make struct that can keep whole state of player or AI pawn.
  • out of that struct make DATA ASSET , either in C++ or blueprints that can hold such struct, this will allow you to make default player and enemy state that you can just load as asset from HDD
  • now you have structs and data assets, so make array in game instance (or any place that survives level load)

If you ever plan to use C++ best place would be custom game Subsystem, that holds that stuff (it is like game mode or game instance, but your own object).

Thanks!

I did start having a POD struct for game state, but it does become tricky with the GAS as the dynamic gameplay effects applied to the player (buffs) would need to be “shadowed” somehow in the data structure. That seemed both like twice the work and error-prone.

My latest thinkings are either:

  1. Serialize the GAS data to a memory buffer before the battle and restore it afterwards.
  2. Dump GAS entirely and write an easily clone-able data structure.