x

Search in
Sort by:

Question Status:

Search help

  • Simple searches use one or more words. Separate the words with spaces (cat dog) to search cat,dog or both. Separate the words with plus signs (cat +dog) to search for items that may contain cat but must contain dog.
  • You can further refine your search on the search results page, where you can search by keywords, author, topic. These can be combined with each other. Examples
    • cat dog --matches anything with cat,dog or both
    • cat +dog --searches for cat +dog where dog is a mandatory term
    • cat -dog -- searches for cat excluding any result containing dog
    • [cats] —will restrict your search to results with topic named "cats"
    • [cats] [dogs] —will restrict your search to results with both topics, "cats", and "dogs"

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.

Product Version: UE 4.21
Tags:
more ▼

asked Mar 01 '19 at 04:09 PM in Blueprint Scripting

avatar image

rokkie199
16 3 1 2

(comments are locked)
10|2000 characters needed characters left

1 answer: sort voted first

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.

more ▼

answered Mar 01 '19 at 04:38 PM

avatar image

BrunoCaxito
175 2 7 6

avatar image rokkie199 Mar 01 '19 at 05:19 PM

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.

avatar image BrunoCaxito Mar 01 '19 at 05:41 PM

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)

avatar image rokkie199 Mar 01 '19 at 05:59 PM

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 :)

avatar image rokkie199 Mar 01 '19 at 06:28 PM

alt text 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.

avatar image BrunoCaxito Mar 01 '19 at 07:10 PM

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.

alt text

On LockWidget "Pre Construc Event node":

1 - Get save game object reference

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

alt text

3 - Proceed with logic

0.png (32.9 kB)
1.png (76.3 kB)
avatar image rokkie199 Mar 01 '19 at 07:18 PM

Great, thank you! :)

(comments are locked)
10|2000 characters needed characters left
Your answer
toggle preview:

Up to 5 attachments (including images) can be used with a maximum of 5.2 MB each and 5.2 MB total.

Follow this question

Once you sign in you will be able to subscribe for any updates here

Answers to this question