Cooldown for spell on a widget?

I have created a spell with a cool down. When i fire the the spell, i want it to trigger the widget to be darker and have numbers on top of it signaling is it is on cool down till it is ready. Is this possible?

Something like this should work.

This is assuming your widget is a button. Add a text box on top of the button and set its default visibility to collapsed or hidden (make sure this text box has the “is variable” checkbox ticked at the top of the details window).

Then go into your button and in the Style section (where you presumably already set up the image your button uses for Normal, Hovered, Pressed and Disabled), change the Tint value in the Disabled state to be darker. This way when you disable your button, it will become darker.

The setup below assumes you want to display tenths of a second in your cooldown text but if you don’t, just change the time value in the Timer Delegate node and the Minus node to 1 second.

1 Like

I have tried to follow the blueprints but cant seem to get the “Set text” function. How would i go about creating this? When i type it in in the Node field, i don’t see it.

Alos, my “sets” in the blueprint don’t have 2 inputs and outputs.

If your Set variable nodes don’t have the colored output it just means you are not on 4.7, but that’s fine. Just Get CooldownRemaining and plug it into the first To Text (Float) box.

The Set Text node can only be found by dragging off of a reference to your Text object in your widget.

In the Designer view of your widget, select your Text box that you added, and then at the top right of the window, where the Details tab is, there is a checkbox next to the name of the text box that says ‘Is Variable’. Make sure that is checked.

That will create a reference to the text box in the variables list in the Graph view, which you can then drag into your graph and get the Set Text node from.

How does this know when i cast the spell? I want it to be so when i click 1, it will do this.

That part is more complicated than it should be right now because of bugs with the engine.

You’ll need to create a Blueprint Interface in order to communicate to your widget. This is necessary to get around what are called circular references, with which UMG has some issues right now. Basically you cannot have your UMG widget refer directly to, for example, your player controller, and also have your player controller directly refer to your widget. That will work fine until you restart the engine, at which point the link between the two will break. A Blueprint Interface acts as a sort of barrier between your blueprints. Blueprint 1 literally hands a message to the Interface, who then hands it to Blueprint 2, but Blueprint 1 and Blueprint 2 never interact directly.

So you will want to have either your widget directly communicate to other blueprints, and all those other blueprints use the interface as a barrier, or the other way around. For this example we will use the former.

With that in mind:

  1. Create a new Blueprint Interface. Call it something like UI Interface.

  2. Add a function in that UI Interface called something like “Trigger UI Spell Cooldown”

  3. Add a new Integer input to that function, name it “Key number” and save.

  4. In your Player Controller (again, I’m assuming that is where you are detecting the keypress that activates the spell), click on Blueprint Props at the top of the window and then at the bottom left of your blueprint window, add the UI Interface to your Player Controller.

30094-capture.png

  1. Do Step 4 as well for your widget

(Continued below)

  1. Add a reference to your widget in your player controller. How this is done depends on where you create the widget and add it to the viewport, but since you’ve presumably been able to create the widget and add it to the viewport already, I’ll assume you can figure out how to save a reference to what you just spawned into your player controller or any other blueprint.

  2. Grab that reference, drag it into your graph, drag off its output and type “Trigger UI Spell Cooldown”. You’ll see a “Trigger UI Spell Cooldown (Message)”, click that. That is what will send the message to your widget, through your interface.

  3. In the “Key Number” input, enter whatever key number the player just pressed to use that spell (I’m assuming you’re using the number keys like in an MMO).

  4. In your widget, right click and type “Event Trigger UI Spell Cooldown”. That is the event that will be triggered when the player controller sends the message through the interface. Add that event.

  5. Drag off the Key Number output from the event and do a Switch on Int. Just add pins until you have numbers 0 through 9, and that way you can just use the same event to trigger all of your spell widgets, based on which key the player pressed, instead of creating 1 function in your Interface for each key.

  6. At this point just plug your existing widget cooldown functionality into your switch and it should work.

Let me know if you run into any problems, I wrote this all off memory so I may have forgotten a part.

Can you help me still? I’m not using the player controller to detect the key press. I am using a blueprint called “My Character” Which is the default blueprint for movement & settings for the character. This is the one for the 3rd person template that has touch input, jumping, movement, and gamepad built in already into the blueprint.

You can follow the same steps but use My Character instead of the controller.

Sorry for all of the replies i’m trying to learn. Can you show me how to add the reference? Should it look like this? If so, i can’t seem to get it to work.

Where are you spawning your widget? Or have you not been able to get your widget on-screen yet?

This is how you should spawn it and create the reference to it in your character. This is from my project so obviously the name of the widget and variable (Player HUD) will be different, and so will the cast (you want to cast to My Character in your case).

The variable in My Character that you are saving your widget reference into needs to be of the type of your widget (Spell Widget 1). Don’t use the purple version of it in this case; purple variables are Class references, not Objects references. You want the blue one.

The difference is that a Class reference is basically just a ‘slot’ of the type you specify. It does not refer to an actual object spawned in the world or displayed on the screen, it’s basically just a definition of what that type of object is in a dictionary. An object (blue) reference refers to a specific instance of an object of that type, something that exists in the game right now.

What I am doing by saving the “Return Value” output of the Create Widget node in my screenshot, is save a reference to that specific widget I just spawned with that node, so that I can directly access it later.

I’m sorry im still confused, im trying my best and can’t seem to get what you are doing. I’m very sorry for all the troubles. So far i got everything you have except for the hud the cast is going to. I don’t spawn in my widget like you are refering to. I used the settings for the widget to do it. Should i not do this and create a hud?

My Widget:

When you play your game, do you actually see your widget on the screen?

Yes, i do.

This is where i have done the position of the Widget:

Where are you adding that widget to your viewport? Can you show a screenshot of the Create Widget node you are using?

Your widget would not just magically show up in your game, so you must be adding it somewhere, and that’s where you need to save the reference to it after creating it.

Very sorry for the late response! I’m just excited to get this to work so i went on a spree trying to find that widget and where i created it. Turns out i put it in the Level Blueprint. So, When i Cast to My Character, then try to set that Blueprint it is not there. I also tried to make a variable but i could not find it.

Here is a picture of my Create Widget Node.

You don’t want to use the Level Blueprint for things that are not level-specific, since those things will no longer work outside of your level.

Something like the UI is not level specific and should be created in another blueprint.

Start by removing what you put in the level blueprint, then:

  1. Open MyCharacter

  2. Add a variable of the type Spell 1 Widget (remember, blue, not purple)

30552-capture.png

  1. Create that widget from the Event Begin Play node in MyCharacter, like you did in the level blueprint.

  2. Save the Return Value (what was just created by the Create Widget node) into the variable you created.

That variable is the reference that you want to use in the instructions I posted several posts above. Remember that in your case, when you’re following those instructions, do the Player Controller parts in MyCharacter instead, since that’s where you’re detecting the keypress.

I have set everything up and followed all of your instructions but still can’t get the text to show on the button. Is there something i did wrong?