WIDGET stays receiving inputs and working after remove

I have a widget with inputs and logic inside.
once I remove from parent it stays getting the inputs and
acting. I dont understand why epic did the destruction of widget different
to actors. It is supposed the way to ‘destruct’ a widget is just by removing
from parent but it seems that is false. even setting the widget to disable
before removing from viewport it stays receiving inputs and working.

How do i solve this?

doing this simple test: “U” disables and removes from parent. “I” says hello :frowning:

setting input mode to UI only for the widget and then removing
seems to work but WILL THIS THING WILL STAY THERE?!?!
So sketchy

no is not working…even the SET INPUT MODE UI ONLY node
has a connector for a widget it overrides the whole game inputs so
the widget stops triggering inputs but the whole game does the same.

I dont want to put some stupid IF conditions to every input just to ignore
the undestructable widget

the worst solution of the universe

Upon unloading the widget with “Remove from parent” you need to clear all references to it in the blueprint variables and call Collect Garbage.

It will be cleaned up and stop taking inputs. If any references to it will not be set to nothing (like my set node at the bottom) it will remain in memory and take further inputs.

3 Likes

I suspect the only BP references to the Widget are the input key node bindings.
Is there a way of unbinding? If not I can try moving this logic to PlayerController
or somewhere else.

Since we can take advantage of Enhanced Input (why aren’t you?!), consider building on what it can do - Mapping Context is dynamic.

Imagine a scenario:

  • I have a character that moves with WASD
  • I have a backpack UI whose grid I also navigate with WASD

Open Backpack → Add Backpack Mapping Context with higher priority that also consumes input
Close Backpack → Remove Backpack Mapping Context

I can use WASD in both, but when backpack is open, the character does not move. When backpack is closed, it has no mapping since we removed it.

And I did not need to disable input, or change input modes.

1 Like

You can clear the reference by setting it to “select asset” it basically makes it a nullptr to be cleared by the garbage collector.
@Everynone has the right idea with using the enhanced input mapping context. I guessed you might be using the old legacy input for your own reasons.

1 Like

This, ofc, should work well enough. I’m forced to do it every now and then, too.

I dont understand why epic did the destruction of widget different
to actors.

:person_shrugging: …and inserting widgets into containers at index…

what do you mean with setting it to “select asset” ?

image

Clear the reference, nullify it. If a widget is no longer referenced, it can be garbage collected :crossed_fingers:

you are right I am using legacy inputs because I am a lazy old animal LOL.
anyway do you think my problem with the immortal widget is because it uses Input nodes in the BP? if so I will go for the supercool new enhanced inputs :slight_smile:

yes but I dont have the widget on any variable…just create—>add…later it removes itself so nop need to set anywhere.

add…later it removes itself so nop need to set anywhere.

Garbage has yet to be removed from memory, though. It clumps up objects together first into a neat bundle, waits (up to a minute or thereabout) and then releases it. You can force early garbage collect but it may choke a bit.

the immortal widget is because it uses Input nodes in the BP

The thing is that before UE5 and EI, you would not be able to do this:

image

So it was not even an issue. You had to override on key down (which you still can!). Now we can use direct input in widgets so the legacy system becomes… unusable in this very fashion.


image

You’d need to grant the widget keyboard focus and then it can start detecting any key, your job is to filter what you want. That’s the old school way.

1 Like

Ok…main issue is not inputs…its a widget that keeps reciving inputs after being destroyed.

I did this simple test.

Player Controller: (C - creates widgets of a class, D - removes all widgets of a class, E - counts widgets of a class)

the widget:

note I included an input in the widget on purpose.

everything works perfect…all widgets are actually removed and deleted even having an input so my problem is not that. I guess I still having it referenced somewhere but i dont have idea because I just create the widget and later I remove it from widget…no SETS.

will watch for the reference viewer…I mean…I access the widget from other actors but as getter…I never store a reference of it (at least that is what I think)

widget has prematch in its name…this is the global search on BP:

image

this are the uses:

image

as you note most usage outside of the widget is just trying to get rid of it LOL

So this prints 0 and your input still works? Collect garbage here:

1 Like

collect garbage is the final solution :heart:

thanks man!

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.