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"

Office Holiday

Epic Games' offices will be on holiday from June 22nd to July 7th. During this period support will be limited. Our offices will reopen on Monday, July 8th. 

How can I set up an AI health system?

Hi! I'm pretty new to ue4 and can't find a really suiting tutorial for this.. I've a working AI that spawns on a location, walks to random spots on her nav mesh and as fast as I enter the nav mash she runs towards me.. Now to my problem.. When I wanna shoot her I need some sort of health system on her.. Now when my projectile hits I only get my print string.. What have I done wrong or have I missed something important out? I'll add some screens to my two blueprints :)



Oh and ye, I'm using the FPS-bluprint project Cheers

Product Version: Not Selected
more ▼

asked Sep 23 '14 at 05:49 PM in Blueprint Scripting

avatar image

1 4 6 6

avatar image ZaikuSasori Jun 27 '15 at 03:56 PM

I managed to make a much simpler version of what you'd put into the second screen shot and got a health system for enemy AI which can easily be implemented to any character.


Sly edit here: Realised a better way of handing the health check, which was to deal the damage first and then have the set command execute the check after it completed. the below can now be ignored unless you wish to circumnavigate my horrible drawings and replicate the original version.

Note: For some reason, even though the value function on that blueprint is less than or equal to, it seems to only respond to less than for destroying the actor, as I had the health default set to 10 and it died after 11 bullets. That or it destroys on additional damage after it hits zero because the function to check health isn't being called until it receives damage once again after it goes below the value..

Either way, it seems to be that the best way to avoid having to do a constant health check for all actors on every tick is to just set that value to 1 so it can die on 0. Sorry if my explanation isn't all too great, but the blueprint should have all the info you need either way.

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

1 answer: sort voted first

Well does it have HP and a handle for the damage?

Within your actor you need to grab that input and handle it somehow. There should be a node called "took damage" or very similar which receives all kinds of "apply damage" events and allows you to calculate shields and all that stuff.

TLDR: You already deal the damage. Now you need to put a HP system behind it.

more ▼

answered Sep 23 '14 at 06:27 PM

avatar image

5.9k 291 86 293

avatar image Golge Sep 23 '14 at 06:33 PM

Yes, I know.. But I can't find any good health system tutorial that is working for me :/ Have I done someting wrong on the "HP?" blueprint?

avatar image Erasio Sep 23 '14 at 06:37 PM

HP blueprint?

HP should not be more than a variable within your AI character (so not the AI blueprint or the behavior tree but the character which the AI possesses).

You receive the applied damage, subtract it from your current HP and set this as new HP value.

If you go below 0 you destroy the actor or do whatever your actor should do when he died.

That's all logic you will have to implement yourself. There is honestly not much too it...

avatar image Golge Sep 23 '14 at 06:41 PM

Ye. check this http://i.imgur.com/T6taNeV.png :) On the bottom of this picture I've tried to make some sort of health system inside my AI's blueprint, maybe it's completely wrong?

avatar image Erasio Sep 23 '14 at 07:05 PM

Have you tried printing on the event "any damage"?

avatar image Golge Sep 23 '14 at 07:32 PM

Added a print string and nothing happened.. Seems like my hp system doesn't react when I hit my AI :/

avatar image Erasio Sep 23 '14 at 07:56 PM

Ah wait. I see the problem.

In your Projectile class when you apply damage you apply it to your player character and not to whatever got hit and you also only apply damage when the hit actor is the player character.

Just pull out the "Other Actor" line and directly put it into "Damaged Actor". You can do the checks later on at the actually hit actor... or just ignore it all together. Nothing is happening if you don't have a "took damage" node.

avatar image Golge Sep 23 '14 at 08:08 PM

oh okay! I see :) I'll try it out. Thanks lad

avatar image Golge Sep 23 '14 at 08:51 PM

Hmm.. Where should I have the "took damage" node? I can't get it to work.. wow, I must be slow :D

avatar image Erasio Sep 23 '14 at 09:30 PM

You had it pretty much.

You need the HP system pretty much like you had it in the character with the "AnyDamage" node and for the "ApplyDamage" node just pull the "Other Actor" to the "Damaged Actor". Remember to always check where something doesn't work.

Always check if anything at all comes out of the "Any Damage" node and if you have a signal right before you use the "Apply Damage" node.

Oh and get rid of that branch. You probably don't even need the ComponentHit but can use straight up "Event Hit" and pull that straight to apply damage.

avatar image Golge Sep 24 '14 at 10:42 AM

Thanks alot man! Now it's working correctly :)

avatar image Adam Davis STAFF Sep 23 '14 at 08:18 PM

Hi Golge,

Currently you have the damage set up to hit player 0 only. You should set damaged actor to "other actor". You can also do a cast to from your actor to your ai class, then run the damage from that. This makes it check to see if what you hit was an AI, and if so, deal X damage.

avatar image Golge Sep 23 '14 at 08:36 PM

Hmm.. I can't get it to work.. :/ You want me to drag "damage actor" from apply damage back to "other actor" on OnComponentHit?

(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