Problem with access to actor variables without casting

Hello!

There is a problem with access to the variables of the actor (Blueprints).

For example:

The actors are created after the start of the level.

At one level we are have 50 actors (bots) of different types (orcs, goblins, gnomes, dragons, etc.).

All of them have a variable “HP”.

How can get access to variable “HP” or other component of a particular actor without casting?

Parent them to a ‘NPC’ blueprint that has a ‘hp’ variable. That way you can just cast to a ‘npc’ bp without worrying about which specific actor is referenced.

Thank you Salm. This is really good idea. However, maybe there are other ways to solve, more universal without hierarchy of actors? It is interesting to hear other possible solutions.

Well, you could also use an interface. Add a ‘NPC’ interface with a GetHP function, but then you’d have to implement the function to each BP. Just in case you missed it, have you checked out ContentExamples? I’m thinking of the PowerUp pickups and child variations.

You could also try to put a map linking actors->HpValues in your gameinstance, but I haven’t tried that.

Now I’m use array’s in GameInstance to save all NPC’s, Buildings and other interactive actor’s on level with self references and other data. When i need interact with someone of them i just check selected with equal actor from array. But this metod not flexible and not so fast.