Widget duration

Hello!
I am making a sidescroller game where player must collect 10 items to unlock the door. When he collides with door Collision and he has not collected 10 items , a widget appears, which says that he must collect 10 items to unlock the door. The widget must dissapear after 5 seconds. This is working, when the player colides with the door only once, but the problem is that the widget is showing forever if the player collides two or more times… How can I prevent that? Please help me!

Here is my graph.

You’re probably creating more then one widget, but since the delay node is already active, it ignores the second and the next calls.
You need to save the created widget to a variable, and check if this variable is valid before creating the widget; if it’s valid, do nothing; if not, create one. This way you’ll make sure that no more than one widget exists at the same time.
And after the delay and removing from parent, set the variable to NULL (just leave the input pin empty), because the widget remains valid for some time after you remove it, so you need to do it manually.

1 Like

Tuerer, can you show me that with nodes ?

Something like

Looks like your Widget Ref is not getting cleared after the last node. As a workaround I would drop the IsValid node and replace it with a boolean flag.

When your game start boolean_variable = false
When the trigger start if boolean_variable = false keep going and set boolean_variable = true
When your trigger ends set boolean_variable = false

Few things:
After a delay node you should first do an IsValid check on the WidgetRef as a best practice, since it might be invalid already. Setting the WidgetRef property to nullptr is not required because the engine does this automatically for UObject pointers. RemoveFromParent does not immediately destroy a widget and nullptr the property but it is worth noting.
Might want to implement a check on that overlap event to make sure only the player actor overlaps, so that the creation of multiple widgets, or creation at the wrong moment, is not possible.
It’s also unusual to not set the OwningPlayer because this prevents OnInitialized from executing on the created widget.

1 Like