[Performance] Actor / Object / ActorComponent / Structures

Hello over here :slight_smile:

We’re unsure of what is the best practice performance-wise to achieve a particular goal and we would like your help to figure it out.
We already know how to do everything I’m mentioning, we’re just unsure of the road to take.

The situation
We have Player, **Enemy **and Weapon classes.
Each of them have an array of a Stat class like “health” or “damage” (with current / max and starting value of that stat).
We have a StatModifier class that can modify any stat we want.
We have a Perk class that has a list of stat modifier.

The question is: what type of object should be Stat, **StatModifier **and Perk in our case?

With several conditions to keep in mind:

  • these classes will have their properties customized in the Editor and at Runtime
  • we will need to create hard coded StatModifier (meaning inheriting properties of StatModifier)
  • we need to keep track of the current StatModifier applied to any entity at any given time
  • we need to keep track of every stat of every entities that hold some at any given time
  • StatModifier can be added and removed to a Stat at Runtime

Here’s what we’re thinking regarding Stat, StatModifier and Perk:

  • Using Actor -> Not possible performance wise if I’m correct considering each enemy will have something like 10 stat spawned with several statmodifier and maybe one perk each
  • Using Actor Component -> Sounds possible but I’m unsure of the cost performance-wise and it’s not the best usability once implemented
  • Using Object -> I’m not sure of the cost performance wise considering the amount of Stat / StatModifier and Perk spawned in the world
  • Using Structure -> Sounds really interesting performance-wise but we’re not sure if it will fit our needs in the long-term because we never dag much in that area

What should we use? Is there even another way we didn’t think of?

And here it is.

If you have any hint or information, thank in advance. If you have any question feel free to ask!

Looking forward your answer :slight_smile:

Performance-wise your biggest hit will be if you are processing these stats in a tick method. Regardless whether they are in the actor or component, if you are ticking each and every frame you will use up CPU resources. Best practice is to put the stats somewhere sensible and modify them based on events, rather than polling each frame.

As for where is best to put them, object-oriented design will tell you to put them with the logic responsible for them, probably as actor in this case. I can’t see a huge problem putting them in their own component either though to be honest.

I would look to see how the AbilitySystem was implemented as a lot of what you are doing and desire is similar to it.

On top of that the StateModifier sounds like it would work as a UObject. Don’t be so concerned about performance right out of the gate. UObjects can be instanced and you can edit inline as well. It sounds like you are going to be making a Mutator. There are some examples on Tom Looman’s blog and the UT source code.