Description

This is a bug introduced with 18468289 a while ago. We added this functionality for [Link Removed], which allows input event nodes to be placed within widgets and have them behave correctly. 

This is all working well, except for the fact that the input delegates are never unbound. This obviously poses a problem if you have widgets who are regularly created/destroyed. We don't see this much in Lyra/FN because we hide/unhide the widgets rather then completely destroying them most of the time, but this is certainly a problem.

 

Proposed fix from user:

    if(APlayerController* PC = GetOwningPlayer())
    {
        if(PC->InputComponent)
        {
            PC->InputComponent->ClearBindingsForObject(this);
 
            for(int32 BindIdx = PC->InputComponent->KeyBindings.Num()-1; BindIdx >= 0; --BindIdx)
            {
                const FInputKeyBinding& KeyBinding = PC->InputComponent->KeyBindings[BindIdx];
                if(KeyBinding.KeyDelegate.GetObject() == this)
                {
                    PC->InputComponent->KeyBindings.RemoveAt(BindIdx);
                }
            }
        }
    } 

 

I think that this is the "correct" solution, but I would prefer if we could add this functionality to `UInputDelegateBinding` via a "UnbindInputDelegates` function or something so that it can be used elsewhere. This may also get expensive for things with a lot of bindings, so we probably want to optimize it a bit. 

 

Steps to Reproduce
  1. Create a user widget
  2. Add an Enhanced Input delegate to the BP graph for some mapping that is applied to your player already
  3. Create and destroy this widget a bunch of times
  4. Notice that the keybinding delegate arrays will grow continuously

Have Comments or More Details?

There's no existing public thread on this issue, so head over to Questions & Answers just mention UE-205313 in the post.

2
Login to Vote

Unresolved
ComponentUE - Editor - UI Systems - UMG
Affects Versions5.1
Target Fix5.5
CreatedJan 30, 2024
UpdatedApr 25, 2024