I have a health bar enemy widget over the enemies. The health variable changes for each new wave when enemy monster respawn and they get additional health. So basicly to make the widget health bar move accordingly to the damage i do it has to be divided by the same amount the health currently is. For example 200 health has to be divided by 200 then then the bar moves with each damage hit and when the next wave starts and the health amount is for example 250 so then again it needs to be divided by 250 and so on.
It looks like this
This example works only for the first wave when the health is 200 as well but after the wave the health increase and the divide by 200 isnt working anymore.
So i tought i may just need to get the "life amount and divide it by itself and hook up the âlife amountâ there instead of 200. But then the health bar just stops moving
The âLife amountâ is comming from a simple Interface which updates correctly the new values (on the right you see that it has value 0 but it acctually updates in the moment i shoot and hit an enemy and sets it correctly to 200 for example and maybe thats why "life amount divided by âlife amountâ isnt working and it kinda thinks is 0 on this one) So now im not sure how i can make this working any tip how to solve this would be greatly appreciated.
can you give any more detail how i can do this or any tutorial where i can see how its done ?
I just tried to make the variable life remaining in my enemy BP where the dmg logic ist with a print string and it shows me the correct numbers with each hit life remaining is looking good as expected i do 10 dmg so it go from 250 then 240 230 and so on so must be correct i guess
Ok so 85/250 means i need to reverse divide the remaining life divided the life amount but for some reason my health widget dont show up i guess my casting from the enemy reference variable is false there ? if i print string it it shows me 0 so that must be it
If i do this the widget dissapiers i think the casting is false the reference to the enemy isnt working i think and print string shows me value of 0 when i hook the life remaining variable to it
Yes it is in the enemy and i made an Interface for it
No this is in the widget itself on the progress bar then âbindâ function it may be better to call this on the player right ? I mean more efficient for performance ? and should i try some thing like this maybe ?
This looks ok, from what I can see, but you need floats all the way. Otherwise youâre getting integer division, thatâs not going to help.
Using a bind in the widget is absolutely fine for now.
In the long run, or if you have a lot of enemies, then you need to set this from the enemy.
It doesnât make sense to set it from the player, they shouldnât know about enemy damage. They just fire a missile ( or whatever ) and do some damage, but donât know how much until they see the widget.
I guess reference is still not right like this print string dont show up anymore and healthbar is awso gone. Then i tried to make this in the enmy BP and unplug the function in the healthbar from the screenshot above and then i used this
That was the first thing i did as well then i switched to sequence. When i plug it like that or with sequence the healthbar just dissapiers. when i plug in the how much life left node to print string it shows me 0 so thats why the bar is gone at 0 its invisible⌠Not sure why i cant read the correct value of this how much life left. i even made an interface to it so i can read the value without the need of casting⌠Something isnt right as it seems at the enemy BP with this variable
Like here where it is plugged in it reads the correct life left values but only the connected node. I just changed the default value of it to be 300 and now the top screenshot works and the healthbar shows again so befor that it was to 0 value. how can i get the reference to the updated node âhow much life leftâ node which is the connected one top screenshot ? So short version setting this default value does not help i need to get this to aways update with the new values.
I made 2 interfaces just for this 2 values and the wierd thing is the âLife Amountâ variable works perfectly fine like this and aways update the correct life amount but i cant replicate the same with the âhow much life leftâ node
If i can do that i can directly connect the updated life left and current life nodes so like this it should work. Unfortunatly the widget do not show up when i try to connect this âSet percent nodesâ right after event beginn play sadly⌠Acctually it is there but empty at 0 and is still not showing the red filling color nor is anything moving when hitting an enemyâŚ
So after following the health widget guide above the enemyâs head it works flawlessly just like on the tutorial problem is he awso has fixed amount of life i think 100 and then he divides that by 100 so progressbar moves as it should. This is the case for me too but the life increases of my enemyâs so this works only for the first wave of monster spawn. Basicly all i need is to change this like you showed me but i cant get the variables ref to them correctly in the widget BP when i try to get them from the enemy.
If i cant do that i should try to move the widget progress bar not calling it from the âbindâ function on the widget but on the enemy where the correct variables are and updating correctly i think if i can make it to show up from there it may work.
Have to mention that those current life variable changes in the spawner i have in the moment when the next wave spawns. So i made extra an interface just for the current life variable so the spawner can get access to it as well as the enemy BP where my dmg was and the widgetBP. And that works as it seems after each wave the current life increases accordingly. But now i made an extra interface for the second variable the âhow much life is leftâ and this one seems to not work as it should not sure why or how to access it properly in the widgetBP.
This doesnât sound good. I wasted yestarday the whole day working on it but in the end i still couldnât fix it Not sure what to do maybe i should move on for now and try again later. Anyway thx for the help and let me know if you do find something later. Iâm using 5.1 btw
But the widget component should acctually work did you try maybe the same tutorial i posted above ? It works for me just like there but i additionally need to change this 1 variable to be aways up to date is the only difference and the only thing that did not work for me. Widget itself get shown correctly and the health bar moves according to the damage i do, but like i say only when the value is fixed tough on the dividing equation partâŚ
You could use another interface here, but thereâs no point, because you have already declared the widget type in the widget component. So itâs âuncleanâ anyway.
Try this, maybe it works in 5.1
@Everynone : Do you have 5.2? This should work, but doesnât⌠:-/ ( just checking Iâm not going mad ).