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.
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.
asked Sep 12 '16 at 10:41 AM in Blueprint Scripting
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:
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
answered Sep 12 '16 at 08:01 PM
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.
answered Sep 12 '16 at 11:30 AM
Follow this question
Once you sign in you will be able to subscribe for any updates here