So right now, I have a simple Score = Score++ for when the player has scored.
The screenshot attached is of my Widget Blueprint.
It currently works by getting the reference to the players score from a Cast To node. To check if any changes are made to the score, this is just plugged into the Event Tick.
Of course, as it is, the animation I want to play is continuously repeating every frame so it looks like nothing is happening, I just included it in the picture to help visualise what I’m trying to do.
So how could I go about setting this up so the score only updates when the player scores, and with it, the animation plays?
I would not update score on tick, that is pretty inefficient for what you are trying to do. Instead use whatever blueprint registers the player as having “scored” (stackspawn BP?) reference the widget blueprint and update the widget. So basically, when a player scores, update the score in the blueprint you keep the “score variable” then have that reference the widget and call a function you set up in the widget. The function in the widget will reference the player character or whatever blueprint is storing the “score variable” set its text to the new score and then “play animation”. This way the animation only plays when the score is actually changed instead of every tick.
Wherever you register the “scoring”…that blueprint would then have to cast to game mode to retrieve a reference to the widget BP to then modify the text in the widget. So basically if set up as below the steps would be as follows:
Game Mode: creates widget
Player Character: registers “score”/holds score variable
Player “scores”
Score is updated in player BP
Player BP references “Game Mode”
From Game Mode Reference, “created widget” is referenced
Call function in widget to “update” widget text to reflect player score
Make sense? I have added screen shots to explain better, hope it helps.