Download

Boolean not casting properly inside UMG Blueprint

Hi! Im trying to cast a simple Boolean that I set in my character blueprint to my UMG to let my widget know when my key is no longer held, so that it can destroy itself.
However, the Boolean in the UMG seems to disregard how it’s set in the character BP, and gets set to True in the UMG blueprint regardless. What am I doing wrong?

nzCddAp.jpg

I would like to set up my blueprint in a way that the Widget would destroy itself without finishing when I let go of the input key, I haven’t had much luck in achieving this yet.

I’ve uploaded my blueprints here so its easier to see

https://blueprintue.com/blueprint/ywkusxjc/
https://blueprintue.com/blueprint/nvr8r7f3/

Seems to me that you’re testing it in the wrong place. “Event Construct” will run when the widget is constructed only so the variable will always be true. You would need to check if it’s false on another function, it would work on Tick for instance. Though what I really suggest is for you to create a “Remove” function in your widget and call that when the key is released.

Concur with homembarata… But even with Tick you may see some timing issues…
I favor adding a Custom Event inside the Widget that you can call from Character.

Or

Pass in a Bool value, or have a Bool already inside the Widget ready to be set etc…
Overall you risk losing time on these kinds of coding glitches, so a few suggestions:

  1. Fix the problem for now using Event Tick inside the Widget (no Construct).

  2. Add a Print-String to catch any ‘Cast Failed’ failure inside the Widget etc.

  3. Hide / Show the Widget, instead of creating new instances on a Keypress.
    (Store the Widget in a variable inside the Character, toggle Widget Visibility)…

  4. Have the Character write a copy of the Bool to the Widget not refer back.
    (Rule out another instance of the Character being spawned in the level etc).

5 .Swap the Bool for Enum / Int etc, as there’s many ways to mess bools up…

Notes:
Overall, a Bool might seem like the easy option here. But the danger is, if the Bool-set code ever gets bypassed it may not be obvious. Whereas Enums are better (3). If you’re not familiar with Enums, you can just use Int: Set the default value of Key-Held to -1. Then you can tell inside the Widget if the variable was ever set and see if there are timing issues. Watch out using Get-Owning-Player-Pawn as well. If you spawn another player pawn, even by accident, or ever add Split-Screen, the object returned may not be what you expect. Overall, try using a Widget custom event for this. But if not, have the Character set an Int / Enum inside the Widget, rather than refer back to the Character. Also use restraint sticking code in Event Construct vs Tick / Custom-Events (fine for cosmetic work, not gameplay logic).

Thank you for the super detailed answer @franktech

I decided to go with custom events instead of a boolean and that works to an extent. Im still not able to get my radial load to function how I want it to for some reason. When the alpha parameter fills up, or when the space bar is not pressed, I want the alpha to be set to Zero and the widget removed.

That way if the player spams the space bar, there wont be multiple instances of the radial load widget. Wont there be multiple instances running with toggle visibility? Not sure what Im doing wrong.

https://blueprintue.com/blueprint/mbwdvua5/

https://blueprintue.com/blueprint/1-or_vxi/

Solved it! I ended up toggling the visibility in the widget BP. Thanks again!

https://blueprintue.com/blueprint/e4x02sc8/