x

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"

Make enemy health bars independant?

Hi guys, just a quick one. I have an enemy (BossAI blueprint) character actor that has a widget component whose widget class (EnemyVitals3DW user widget blueprint) shows the enemy's name and a health bar.

alt text

The problem I have with my implementation is that if I duplicate the enemy blueprint all of the enemies share their names and health bars with the first instance of the enemy. Though I have tested and each enemy has their own health and can be destroyed independently. I feel like I know what I need to do, to tell the 'cast to' node to select the correct instance of the enemy that corresponds to itself, but I can't for the life of me figure it out.

Sorry if this is a simple fix but I would really appreciate it, because as soon as I feel I have the hang of blueprint communication I always hit a stumbling block such as this.

Product Version: UE 4.12
Tags:
more ▼

asked Sep 12 '16 at 10:41 AM in Blueprint Scripting

avatar image

Jarrastafari
31 2 3 8

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

2 answers: sort voted first

Ok, so since I couldn't figure out how to cast to an instance of an enemy and have their health bar display their own health and not their progenitors, I have explored and combined two different approaches to achieve the same result.

If anyone gets as stuck then please see the following two tutorials:

alt text

First, I decided to use event dispatchers, as explained by Zak, to update my player characters HUD. Even though I felt I was completely familiar with casting and interfacing with blueprints (obviously I wasn't) I found the whole video is a great refresher, as he does well at explaining the different methods of blueprint communication and their uses.

Second, I used Tesla Dev's method for my enemy HUD and found that each instance of the blueprint would read their own health correctly and so resolved my main issue.

Lost 10 hours of work today tackling this issue, but after rewatching Zaks video and working through to a solution I feel my understanding of the engine has improved. Overall it has been worth the effort and the stress. Hope this helps advice can help someone.

Love & respect, Dan

solution.png (1.6 MB)
more ▼

answered Sep 12 '16 at 08:01 PM

avatar image

Jarrastafari
31 2 3 8

avatar image Bluemak Apr 07 '17 at 09:55 AM

Thank youuuuuuu!!!!!!!! This fixed my problem as well :)

avatar image Jarrastafari Apr 07 '17 at 10:15 AM

Glad I could help. Stick with it and you can succeed.

Love and respect, Dan

avatar image Nemean Aug 30 '18 at 06:33 PM

Thank you for the link on BP Communications, it's been incredibly informative.

avatar image Jarrastafari Aug 31 '18 at 04:14 PM

Excellent. Good luck!

L&R

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

Hi,

Why do you you iterate on all actors of your BossAI class to update UI ?

You should directly your blueprint widget component from your HP and Name variables. This implementation is more optimized and easier to debug.

Otherwise, your problem is you never check the current element in your array is your current actor. The Cast return the object with the type you asked if possible, it doesn't check if your instance is the same as the Self instance. You must check Array Element is equals to Self reference.

But again, I don't recommend you to keep continue using your implementation.

more ▼

answered Sep 12 '16 at 11:30 AM

avatar image

KevinDrure
100 9 12 19

avatar image Jarrastafari Sep 12 '16 at 11:40 AM

Thanks for the reply, HellSuffering.

I am happy to cut out the array, as I simply used it to get an object reference in the first instance.

alt text

Could you please state which node(s) I can use with the Cast To object reference that would identify the BossAI that each user widget is associated with? I have tried plugging in everything I can think of (e.g. get user widget object, etc.)

avatar image KevinDrure Sep 12 '16 at 12:16 PM

You don't need to Cast anything, Cast is just a type conversation to get an object of a type to another compatible type (main key of polymorphism in object oriented langage).

HP and HP max are variables on your blueprint, you just have to return HP / HPMax because these variables are owned by your blueprint instance. You just have to link it to your widget progress bar percent propertie. So each instance of your blueprint have their own HP and HPMax vars.

avatar image Jarrastafari Sep 12 '16 at 01:25 PM

Very grateful for the advice.

Unfortunately I hold the HP and HPmax values in the BossAI (enemy character) blueprint, so to access them I would have to cast (no?). If I remove the cast and just select get HP and get HPmax nodes from the BossAI blueprint, I end up with an error. Which makes sense to me, as I haven't setup any communication between the two.

alt text

I am reviewing the Blueprint Communications video now, but I feel like I know what I want to do but I am missing something obvious. Perhaps I have misunderstood you.


To be clear, I have:

  • BossAI (the enemy BP) storing HP and HPmax values as Int

  • a user widget (EnemyVitals3DW) that draws a health bar and name plate for the enemy

  • a widget component in the BossAI, with it's widget type with it's widget class set to EnemyVitals3DW

And I want to:

  • take the HP and HPmax variable values from the BossAI blueprint

  • get them in the EnemyVitals3DW widget blueprint

  • calculate the percentage and feed that into a progress bar

  • have multiple BossAI characters in the level at the same time with their own health bars


alt text

avatar image KevinDrure Sep 12 '16 at 02:10 PM

I have not understooden you were in the Widget Blueprint.

I don't know very well how to structure blueprint as I almost use C++, but you can try to make Setters on your widget blueprint (method like SetMyVar(int Value)). Then, from your character blueprint, use this setter on your widget component to communicate the value.

(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