Battery drains ingame but not in my HUD. I have copied so many tutorials but can’t figure out what to do
Why not update the widget via the sedan? You are already doing the delay there. Have it event driven instead of constantly polling in the UI widget.
You already have a reference to the widget there.
Sorry I’m not sure what you mean
Use these nodes in your script - you already have a widget reference variable. This way you updated the battery when needed:
Rather than polling data 60 times per second through a variable that will keep throwing errors at your as soon as it becomes invalid. Remove the binding and set widget progress when the battery drains.
Rather than having the widget pull the data out of the car, have the car push the data into the widget.
Yup. Just remove the function binding in the widget because it tries to update the progress bar all the time. Also progress bar is 0-1 not 0-100. Unreal cannot percent
Which function binding?
So I can delete all of that?
Basically I have 4 light switches which drain battery (that part works because my lights all turn off when there is no more battery. However the HUD does not drain and just stays at max battery power.
But for each light that is switched on I want it to drain faster (which seems to be working but I’m not sure. I just want to fix the HUD first)
I would. Unbind. It’s much more efficient to update it via an event.
Runs every frame, is inefficient and makes things convoluted and requires a reference to the sedan BP.
Unless you do want to see an update every frame, it’s easier to have the car update its display, especially that you do it once per second (presumably) only.
This, on its own:
looks spot on. Calculate the drain from all sources and then update the widget once. Just pipe in the correct data. As mentioned above the progress bar likes the 0-1 range, not 0-100.
I deleted and unbinded what you told me to and it’s still not working.
It might be possible the data is wrong… I have no idea what I should set it too though.
I set the percent in set percent to 1.0
My battery variable is set to 100. The drain is supposed to drain it by 1.0 and I have set the progress percent in the battery power widget to 100
Still nothing is working though
You were dividing the
Battery float by 100 before. Are you still doing it? Print the data to visualise the values you’re actually sending to the widget.
The light battery drain in-game works perfectly, it’s just trying to get the HUD to drain.
I deleted that entire function like you said so no I’m not
Feed the progress bar a value in range 0-1.
If in doubt, print the value to see what you’re sending to the widget:
Oh thanks! It’s actually draining now! Not very smoothly however…
And there’s a slight issue… sometimes it will stop draining even when a light is on
We don’t know where this is coming from - I’ll assume it’s Tick + Delay, so it’s a ghetto timer draining it once per second? If so, it works as intended.
If you want smoother updates, you need to run it more often. Or interpolated the results.
This is done for each light switch
The battery is not draining faster the more lights I have turned on. And it does not drain when 1 light is on but I switch off and on another light
Then it’s a problem with the math logic of how you accumulate the battery drain.
Would you know of a way I could create a function so that it increases the amount of drainage when more lights turn on?
I can think of too many ways, actually. How to tackle it depends on the scope. Perhaps you could briefly tell how it’s supposed to work.