Health pickup to multiple selectable characters?

So I’m Following this RPG tutorial Melee Character HUD & Fixes - #22 Creating A Role Playing Game With Unreal Engine 4 - YouTube and the guy is showing us how to let multiple characters that can be selected at the beginning use a health pickup. The way shown is to make a new casting to every possible character. My question is, Is there a better way to do this? It seems unbelievably inefficient to make a new code line for every possible character, especially if I make a larger amount of characters. Could I maybe have it cast to any character that overlaps it, if not what’s a more efficient way?

Make a “Master” Character class, make all your “select-able” characters children of this master class. Add whatever unique functionality you would like to distinguish the characters in the child blueprints. When you want to add health to any of the characters a simple cast to the “master” class will identify if the overlapping actor is a child and add the health accordingly. This way you only need to cast once to the master class to affect any variable in any of the overlapping children. If the variable is common to all create it in the master and this will work. If it is a unique variable to a specific character like a certain ability, you will need to cast to that child specifically however. But for health, I assume all characters will have this variable so, using and overlap event and cast to master will work to change that character instance’s health.

Thank you, that seems much more efficient. I have a follow-up question though, if I do it the way you described that would mean that the characters share health correct? Like if I implement a system where you could change characters on the fly, wouldn’t all damage and healing happen to both characters?

No, each character is its own “instance”. I just laid out a way to “parent” or create a more efficient hierarchy. So within the “master class” you have a health variable. But character 1 being a child of the “master” can have 100 HP, every copy of character 1 will have 100 HP. If one copy overlaps a health pick up, the overlap event will identify the specific actor instance, and your subsequent code will adjust the health of character 1 that overlapped the health pickup only. All other character 1’s in your level will still have 100 health. Character 2 can have health of 200, and still be a “child” of the master character class. When an instance of character 2 overlaps the health pick up its health will start at 200 and increase however much you decide. The purpose of parenting is for situations exactly like you are having right now. It allows you to cast once to a “parent” class and easily modify any variable stored in that class on any instance of any child you create.

I see, thank you, this answers my question perfectly.

Glad to help, Good luck with your game!