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 as a Component or as a Variable on a Character BP?


In your opinions, is it best to have:

  • Health

  • Max Health

  • Is Dead? (boolean - health below 0 check)

As variables on a character? Or as components on a character?


Product Version: UE 4.12
more ▼

asked Sep 07 '16 at 01:18 PM in Blueprint Scripting

avatar image

3 4 4 6

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

3 answers: sort voted first

I know there are a couple ways to do what you're trying to do. There are tags that you can look into using. You could, for example, tag an actor as an Enemy, and make all actors tagged as enemies follow certain rules (like taking damage, having health, etc.) More relevant maybe using parent and child classes. For example, you can make a masterEnemyClass which comes with health, maxhealth, and dead variables already created. From that parent class you can create a child class that would inherit those same variables, but also allow for you to add more. For example, you could make a box class that has a cube for a static mesh. Then you could right-click that class, create child class, and make a red box class. The child inherits all the parents values, but can have its own additional values such as color on the static mesh that will not be applied to the parent

more ▼

answered Sep 07 '16 at 04:37 PM

avatar image

241 8 9 12

avatar image Amelia_Synapse Sep 07 '16 at 04:41 PM

Fantastic :) thank you!

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

For something as generic as health, I'd put it in a component. The component could create damage numbers, handle elemental weaknesses, feed into a combat log, give points for kills, or perform any number of other useful health-related actions that you really shouldn't rewrite constantly.

Sure, you could put that functionality on a base class, but inheritance-based structures start making functionality flow upwards as your game expands until tons of actors that don't need the health code are running it and giving you a headache/slowing down your game.

more ▼

answered Jun 18 '17 at 02:20 AM

avatar image

66 1 6 9

avatar image samnater Jun 18 '17 at 12:18 PM

This is good to know! You can definitely use a combination of both parent+child classes and custom components (that is what I do in my game). It really depends how similar your actors/blueprints are going to be.

For example, my game has 16 enemy characters that all share most of the same functions and components (handling health, spawn location, physics, collision sphere, etc), but have different values for each and different skeletal meshes+animations. Making a parent class with 16 children makes sense here--I just need to go and change the default values to make 16 unique enemy's that all handle the same; adding components individually would be tedious.

However, my parent enemy class also uses a custom component (a widget for a visible floating healthbar) that I reuse on other actors: it is the "progress bar" for buildings that are being built.

Parent+child classes are good for vertical design, and components/functions/tags are good for horizontal design. Both are useful!

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

I'm not sure why you would make them components. I use variables for those...variables in my game

more ▼

answered Sep 07 '16 at 03:13 PM

avatar image

241 8 9 12

avatar image Amelia_Synapse Sep 07 '16 at 04:17 PM

Lol that makes sense. Sorry if it was quite a silly question!

Well, I am quite new to this and had watched this Unreal tutorial: https://www.youtube.com/watch?v=qr4ZjieAQKY Part of it near the end said: "With this new component driven workflow, you do not have to just create a game, you can make a framework that makes building your game easier as you move forward. Now I could have people on my team whose job it was to come up with new things to live in my world, e.g. asteroids/space characters/boss characters. They could just simply drag and drop on the components that they need, or we can write new ones if we decide we need more behaviour."

All of my Unreal projects so far have been just following tutorials from start to finish. I am hoping to practice what I have learnt (and learn more!) by rapid prototyping lots of small game ideas.

I am currently working on one project where there are many different classes of players and enemy AI. I thought that if I had created all of the behaviors and functionality as components, it would make it easier as I could just, say, drag and drop the health component onto each of them.

I have already created health and max health variables in my BaseCharacterBP, but I was wondering whether it would be easier to just have it as a component that I can drag and drop onto all of the other characters I have.

Then, when I start prototyping the next project, I can just pull of the components in and very quickly drop them onto anything necessary.

Kind of like creating a library of behaviors for myself. But I suppose I was probably going a bit overboard with considering it for such simple elements like health.

I have also just found this tutorial: https://www.youtube.com/watch?v=IyaE-ncefak but I haven't watched it yet.

(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