I have a widget made to display a score and a highscore. When the score is higher than the previous highscore I want it to play this animation. By only using Event Construct without a branch(boolean) the animation starts perfectly.
The event tick works when trying to print strings. But when I tried to put it so if the condition or boolean(ScoreAnimation) is set to true THEN play animation. Except it doesn’t play the animation.
I’ve tried to set it up in different ways but nothing seems to work. Is anyone able to help me out with what I am doing wrong?
This is my current set up which I hoped for worked but doesn’t…:
The above does not work because when the Construct event fires, the boolean is false - I assume it’s its default value. Even if you change it later, it does not matter, the Construct pulled the variable before the Tick had a chance to modify it.
Besides, there’s a couple of things that can (should) be done differently here. For starters, why don’t you call the widget’s animation directly from BP Player? And call it only when the score changes, rather than checking it every frame (there might be scenarios when you’d want to calculate player score every frame but somehow I don’t think it’s the case here).
As soon as the player’s score changes, check if it’s the highscore, if it is - Get the animation from the widget and Play it.
You’re almost there. Where did you create the widget? You need a reference here.
Where as in, which blueprint creates the Scores widget.
Don’t. Don’t do anything in the LB unless it’s totally and absolutely necessary. Create this widget in the Player BP instead:
- this way you’ll have the reference ready
- you no longer need to cast
- everything is one place
- and anything else can access the Player Pawn so it can access the widget in case it’s needed
This seems like a very good answer. I am however struggling to find a way to get the animation and play it from my player’s blueprint (BP_Player). Sorry if this is a silly question but I am rather new to widgets. I think the way to do it would be to cast to my widget (Scores), get the animation and play the animation. Except I can’t cast to Scores because it needs an object of which I have no idea to fill in.
Edit Picture of trying to cast to widget to get the animation:
I create the Scores widget within the Level Blueprint connected to the Begin Play.
Picture of Level Blueprint:
Thank you so much for the tip and help you provided!
I was struggling with this for hours and thanks to you I finally got it working. You’re a life saver, now I can continue making my game look a bit prettier with animations.
Lesson learned, once again thank you!