Run animation in widget only once?

Heya. ^.^

I’m trying to run an animation to remove lock symbol from level selection once the player has completed said level. Is there an event that only fires the first time the widget is opened and never after that? Or do I have to make a save game and then save a boolean there to see if the animation has been played before or not? It’s just that I have many levels in my level selection screen and each level has a lock symbol at the beginning, so I would have to add many booleans in my save game to keep track of which levels are unlocked and which are not. Feels like there should be a better way to do this?

I’ll clarify further if something was unclear, and can post pictures if you have trouble visualizing what I’m trying to do.

There is no such event. You can play an animation on Construct Event, but it plays every time this UserWidget is created. You can also do some logic to prevent it from playing again, but there is a problem:

If your levels begin locked, you have to store their status during save anyway, because when the game is closed and restarted, there is no other way to know what happened during the last gameplay session, unless you store changes on disk (save).

Your level script, data struct, save file (can’t tell for sure, because I don’t know your game scripts) should have a boolean/Enum property that tells if the level is unlocked, this property needs to be saved.

When a “Level Selection Screen” is created, each level widget get its status from the save game and shows the lock icon accordly.

When the player completes a level, you should check this property to know if an animation should play or not.

PS: There are lots of other methods and optimizations you can use, for example, if your level progression is linear, you can store just the last unlocked level, and all previous levels knows that they should be unlocked as well.

Yeah currently I’m using the data from highscores to determine whether the level is locked or not, since I can tell if the level has been completed if it has a highscore saved for that level. And the lock icon just basically prevents the button from being able to be clicked with Zorder and then I make the Zorder negative after the level is opened, allowing clicks and hiding lock. But it just plays the “Open level X animation” every time I go to “Level select menu”

So basically the correct levels are getting opened and locked, but they keep getting “opened” every time you go to the level selection screen.

So I suppose I can’t use the highscore data to see if the animation has been played before, so I probably have to make a seperate boolean for “Has animation been played to open level?” Thanks though.

Yes, looks like saving a boolean would be simpler.

But, if on completing level, the player is redirected to “Level select menu” to watch the lock icon disappear, you can also:

If the level widget finds a highscore value, it shows as unlock, if not it shows as locked. No animations.

When the player complete a level, store the “Level Score” and “Level Identificator” in temporary variables at GameInstance.

When he gets to “Level select menu”, the menu checks the game instance for the variables, if they have a value, play respective level widget unlock animation, pass the score to the right place and clean the game instance values.

(Again, I’m not sure if this works with your code)

Yep, thanks for all the ideas, for now I implemented the boolean system to check if the animation has been played, it’s quite a lot of code since I need to do it for each level separately, and save all of them to save game, but at least it gets the job done. Maybe I’ll come back to this later if I figure out a better way to do it. Again, thanks for all the help I appreciate it, I picked up a few things and helped me a lot even though I ended up using the original idea :slight_smile:

Here’s the system I used. Any idea if it’s possible to loop this somehow for all of the indexes and for Lock 2, Lock 3 etc widget? Should probably make a seperate question for that, but I’m not sure.

This should be done by each “LockWidget” blueprint.

LockWidget needs a variable (Integer, Instance Editable), to stores its save game arrays index, let’s call it LevelIndex.

When you place a LockWidget in “MenuWidget”, select it and in Details Panel, edit the variable to match the save game array index it uses.

On LockWidget “Pre Construc Event node”:

1 - Get save game object reference

2 - Get the boolean and score value that matches this LockWidget LevelIndex.

270018-1.png

3 - Proceed with logic

Great, thank you! :slight_smile: