Just as the title says, can I change an image in a widget with a keyboard press event?
For instance, pressing Tab to call a function in the UI Widget Blueprint that changes the texture of an image in the designer.
Just as the title says, can I change an image in a widget with a keyboard press event?
For instance, pressing Tab to call a function in the UI Widget Blueprint that changes the texture of an image in the designer.
Sorry, I’m quite new to UE, so I’m not really used to the terminology. When I had said the “designer”, I had meant the UMG, but I realize now I do only need it to change during when the game is running. However, once I have a function like that, where can I call it from? I’m unsure how to call on widget blueprints from other blueprints.
However, once I have a function like
that, where can I call it from? I’m
unsure how to call on widget
blueprints from other blueprints.
So this is more of a communication question. You will need to be more specific with details then. Who communicates with whom and when? There are too many answer to this atm…
Perhaps you could explain with an example, or briefly say what the end goal is.
Atm, a direct answer to your question looks like this:
But I feel that the scenario on your mind is more complex.
Alright, I’ll try and lay everything out in the open.
Basically, I’m creating a game that allows you to lessen gravity. When you press the Tab key, gravity is decreased to 30%. Press the Tab key again, it returns to 100%. You’re able to switch it back and forth as many times as you’d like.
What I’m trying to do is have an image on the HUD that shows what level the gravity is at in the moment. So when gravity is at 100%, it shows one image, when gravity is at 30%, it shows a different image, with the ability to swap back and forth as the player changes gravity.
This is what my gravity control looks like, within the FirstPersonCharacter blueprint, if it’s any help.
You should be able to hook it up to the Flip Flop:
The above assumes you have a widget with an Image already.
And you can do it like so, too:
Using the Select node is a force of habit. And if you run into weird behaviour with the image not sizing properly, do tell. Ruffhaus Games is quite right about brushes misbehaving.
Yes, but as far as I’m aware you have to set the brush each time you want to do it.
Because of this if, you have made any changes to the brush that you want to persist in the new one you’ll have to copy them over to the new one, or make any other changes you want in the brush struct with each update.
For instance, pressing Tab to call a
function in the UI Widget Blueprint
that changes the texture of an image
in the designer.
Widgets can override input events from keyboard. Doing it run-time would then look something like this:
edit: update the image to clarify as native widget brushes are read-only
But when you say designer, do you mean outside of PIE, as in the editor when the game is not running? Could you clarify?
I’ve had issues with this in UMG, the brush struct being marked is read only, will not update after first being set
Ah, this thing, I keep forgetting about this one! It’s a matter of creating your own brush in the Content Browser and using it like so:
Of course it would be that simple, wow. Well, I finally got it working! Thanks so much for taking the time to explain ^^
Cool! Good tip