Search in
Sort by:

Question Status:

Search help

  • Simple searches use one or more words. Separate the words with spaces (cat dog) to search cat,dog or both. Separate the words with plus signs (cat +dog) to search for items that may contain cat but must contain dog.
  • You can further refine your search on the search results page, where you can search by keywords, author, topic. These can be combined with each other. Examples
    • cat dog --matches anything with cat,dog or both
    • cat +dog --searches for cat +dog where dog is a mandatory term
    • cat -dog -- searches for cat excluding any result containing dog
    • [cats] —will restrict your search to results with topic named "cats"
    • [cats] [dogs] —will restrict your search to results with both topics, "cats", and "dogs"

Health pickup to multiple selectable characters?

So I'm Following this RPG tutorial https://www.youtube.com/watch?v=O5IWOmXqezY&list=PLL0cLF8gjBpqA8DcrhL_O9kD4jsUqhDR6∈dex=22 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?

alt text

Product Version: UE 4.18
screenshot-8.png (477.3 kB)
more ▼

asked Mar 05 '18 at 12:43 AM in Blueprint Scripting

avatar image

12 2 5 8

(comments are locked)
10|2000 characters needed characters left
Viewable by all users

1 answer: sort voted first

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.

more ▼

answered Mar 05 '18 at 12:57 AM

avatar image

Nebula Games Inc
5.4k 28 9 15

avatar image StreamLined Mar 05 '18 at 01:52 AM

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?

avatar image Nebula Games Inc Mar 05 '18 at 01:58 AM

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.

avatar image StreamLined Mar 05 '18 at 02:02 AM

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

avatar image Nebula Games Inc Mar 05 '18 at 02:11 AM

Glad to help, Good luck with your game!

(comments are locked)
10|2000 characters needed characters left
Viewable by all users
Your answer
toggle preview:

Up to 5 attachments (including images) can be used with a maximum of 5.2 MB each and 5.2 MB total.

Follow this question

Once you sign in you will be able to subscribe for any updates here

Answers to this question