How to Play a Widget Animation with Condition?

Hello. I am trying to play some animations in user widget blueprint with some conditions. For example; when character’s health is 100, an animation plays. When it’s 75 another one plays and so on. I checked some tutorials and they show how to play them in EventConstruct. I tried EventTick and it didn’t work either. Can anyone help?

First of all I would try upgrading to UE 4.12 since it’s out.

In the widget designer you can create binds on any widget element (e.g. text). You can create binds to different things such as text or colour.

Once you’ve created a bind it will appear as a function in the graph tab. You can then use the “Get Owning Player Pawn” node to get any variables from the player such as health. Below I’ve created a bind that displays the health of the player.

Instead of creating a bind, you could also set a widget element to be variable and change its values inside the graph.

Hope this points you in the right direction. :slight_smile:

Thank you for the long answer but my question is not about this part. I want to know how to play different animations when that variable changes.

Hey -

Using the example of different animations at different health values, you should be able to setup each animation separately as well as define a condition variable, in this case a health check. In the widget graph, you can then check the value of your condition variable and if it matches the test case, play the appropriate animation. For example, if your max helath is 100 then HealthVar >= 76 would be your conditional check for if the player is above 75% health. If this check is true, you can specify the “high health” animation to play. You can then use other condition checks to control playing animations for “mid health” and “low health”.

Cheers

I made seperate animations. Which event node should I put in? I used both EventTick and EventConstruct with a branch and it didn’t work.

In my case it is ‘shield’. When shield is 100, there is a simple opacity animation. I put a trigger box, when character enters her shield is 100 but animation is not playing.

When you create the widget/add it to the viewport, also get a reference to the widget (promote to variable). Then, when you overlap your trigger box, use the widget reference to call a function that runs your animation (rather than running the animation on Event Tick / Event Construct).

Sorry, I misread what exactly you were after. I wrote this quickly as I was on a 5 minute break and it popped up in my emails as a suggestion. I can see that had answered your question now. :slight_smile:

I am doing that but how can I check if shield is below %50 or between 1 and 10? Can’t do it with EventTick and EventAnyDamage. Because when I do that, it keeps adding the widget to viewport. I am trying and trying but couldn’t find a way to how to keep checking Shield.

In your character blueprint (or wherever changes to shield values are being calculated) I would run the check there. Assuming your shields widget is always on screen, you can make a call using the Get All Widgets of Class node and getting the first element of the array and set it as a variable. Then anytime the amount of shields changes you can use the variable reference to call the specific function that plays the appropriate animation.

You are still not answering what I am asking but okay it can stay as resolved since you keep changing the status. Thank you.

Answers are accepted automatically purely for tracking purposes whenever a staff members posts on them, and whenever you post a comment, the thread is reopened. An accepted answer does not mean that a post is closed, as you are always more than welcome to add a post to continue the conversation on a thread, or to reopen an older, previously resolved thread. I apologize if I am not understanding your questions, could you explain exactly where you are in the setup and what you are trying to accomplish?

I created different user widgets to play different animations based on character’s shield status. I created custom functions to check the shield and put proper animatons to that. What I can’t solve is that where to put those functions?

If character has shield, when she takes damage, shield gets damaged not character’s health. When I put those function on EventAnyDamage, animations play but it keeps viewing the widget everytime somethings hit the character. Same thing as EventTick. Same widgets over and over again.

I want to view one widget when shield is 100, other one when shield is 75 and so on. When shield is 0, all animations play at once which I created.

Which event should I use or how can I do it besides those events?

I am doing that, I created variables to all of them and I am using those variables to remove whichever I want.

But you are still not answering what I am asking. I didn’t ask how to play animation or how to add widgets to viewport or their variables and stuff. I want to know how to check shield value as you can see above your answer.

I want to confirm that you are referring to the to a widget animation (in the lower left corner of your first screenshot). If this is the case, it sounds like you have different widgets for each of your animations. In this situation you would need to remove one widget from the viewport and add the new widget after. With this setup you should be able to play the animation when the widget is created using the EventConstruct. You’ll also want to make sure that the “Num Loops to Play” is set to 0 so that it loops infinitely.

One thing you can do is where ever you are adding the widget to the viewport, begin by creating all of the widgets and adding them to the viewport and assigning each one to a variable. Then use the “Remove from Parent” node to remove all but the first widget you want to use. I’m not sure where your function to check the shield is located, but making this check in the same place that you created the widgets would allow you to use the variable references after each check to “Remove from Parent” the widget that was playing the animation and “Add to Viewport” the next widget with the new animation to play.

I really appreciate your attitude to help, I really do. But we can’t understand eachother. I know those things, I am not new to the engine. I was asking the event to check this since the beginning and you keep answering other things.

I am just gonna wait someone else to answer. Thank you for taking time to answer me last 2 days. I appreciate that.

Shield only changes when character takes damage. Its just EventAnyDamage node. When she has shield, shield takes damage. If not health.

When I put that in EventAnyDamage, widget keeps adding to viewport on every single hit and it multiplies on the screen.

Depending on if your shield variable is an integer or a float value, you would use either the integer > integer or float > float node. The top input pin would be the current value of shields and the bottom input pin would be the value you’re testing against. For instance, if you want the same animation from 100% shields to 75% shields then you would say (shields) > 75 (assuming max shields is at 100). The boolean that is returned will be true as long as the value of shields is above 75. You can then wire the return pin into a branch node to decide what to do if the shields is above/below the test value. If it is above then set your animations, if it is below then run a second check (branch) to test if (shields) >= 50 (for the next “step” down in the animation effect if shields are at or above 50%).

The event to run this check in would be the same event where the value of the shields is changing. Where ever you are doing the computation for “the player gains x amount of shields” should then check “what is the player’s shield total?” If you could provide a screenshot of your setup so far I may be able to provide a better answer.

Can anyone help me with this?