# Weird Enhanced Input Problem (C++ & Blueprint)

**URL:** <https://forums.unrealengine.com/t/weird-enhanced-input-problem-c-blueprint/832485>\
**Category:** Programming & Scripting\
**Tags:** unreal-engine, question\
**Created:** [March 29, 2023, 4:57pm UTC](https://forums.unrealengine.com/t/weird-enhanced-input-problem-c-blueprint/832485 "2023-03-29T16:57:10Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Scon81](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Scon81](https://forums.unrealengine.com/u/Scon81)\
**Post date:** [March 29, 2023, 4:57pm UTC](https://forums.unrealengine.com/t/weird-enhanced-input-problem-c-blueprint/832485/1 "2023-03-29T16:57:10Z")

</div>

I have a strange input problem within a User Widget:

![2](https://d3kjluh73b9h9o.cloudfront.net/original/4X/1/c/a/1ca13d33abe7c601010c2e5df04e9dea4cf7ff7d.png)

When I create the Widget, I add a Input Context and when I destroy it, the context will be removed. This works correct so far:

 ![1](https://d3kjluh73b9h9o.cloudfront.net/original/4X/8/4/d/84d4166da0ec15dd10e02bc56ccd5f8491bd8370.png)

Within the Widget I consume an Input Action:

![3](https://d3kjluh73b9h9o.cloudfront.net/original/4X/d/2/8/d2811a7c58c9af8367247c9b2c0aae68d7918c45.png)

Everthing work fine when I open the widget, trigger the Event and destroy the Widget. The following messages are shown:

1. “Construct”
2. “Confirm”
3. “Destruct”

But when I open the widget again, and trigger the event (press the button) I got the following messages:

1. “Construct”
2. “Confirm”
3. “Confirm”
4. “Destruct”

And if I open it the third time:

1. “Construct”
2. “Confirm”
3. “Confirm”
4. “Confirm”
5. “Destruct”

a.s.o …

I’m using 5.1, the Enhanced Input System and tested it the C++ and the BluePrint way.

Any ideas are welcome.

---

<div class="post-metadata">

**Author:** ![IrSoil](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@IrSoil](https://forums.unrealengine.com/u/IrSoil)\
**Post date:** [March 29, 2023, 5:07pm UTC](https://forums.unrealengine.com/t/weird-enhanced-input-problem-c-blueprint/832485/2 "2023-03-29T17:07:34Z")

</div>

Well, obviously: `RemoveMappingContext()` doesn’t work as you expect it.

Right away I see nothing suspicious in `RemoveMappingContext()`, so you should start from tracing the problem with c++ debugger from here on your project.

Also i’m not sure that pointers to context you passing to both functions are the same, so you should check this as well

---

<div class="post-metadata">

**Author:** ![SolidSk](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/solidsk/32/1194513_2.png) [@SolidSk](https://forums.unrealengine.com/u/SolidSk)\
**Post date:** [March 29, 2023, 8:33pm UTC](https://forums.unrealengine.com/t/weird-enhanced-input-problem-c-blueprint/832485/3 "2023-03-29T20:33:02Z")

</div>

Are you sure you are deleting the previous Widget?  
It seems that every time you ‘open’ a Widget, a new instance is created and this new instance is consuming the input with the previous one.

I tested it with two **AddMappingContext** and the input didn’t duplicate.

[UUserWidget::Destruct](https://docs.unrealengine.com/5.0/en-US/API/Runtime/UMG/Blueprint/UUserWidget/Destruct/)

> Called when a widget is no longer referenced causing the slate resource to destroyed. Just like Construct this event can be called multiple times.

Try to **AddToViewport** the deleted Widget and see if it works.

---

<div class="post-metadata">

**Author:** ![Scon81](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Scon81](https://forums.unrealengine.com/u/Scon81)\
**Post date:** [March 30, 2023, 9:46am UTC](https://forums.unrealengine.com/t/weird-enhanced-input-problem-c-blueprint/832485/4 "2023-03-30T09:46:43Z")

</div>

Thanks for your answers. Today I learned something new.

The Problem was not the Enhanced Input System, but the way Unreal “destroy” widgets.

If you remove a widget with `Remove From Parent`, its `Destruct` event is called BUT this does not mean the widget is destroyed. It still remain in memory AND it still react to events like Input Actions.

With this new knowledge, I have 3 options to solve this Problem:

- Reuse the widgets as I did on others (but this won’t work well with different Popups)
- Call `GarbageCollect` after removing from parent (and after all references are `nullptr`)
- Mark Widget as `Released` and block event from execution

Thanks for you help

---

<div class="post-metadata">

**Author:** ![IrSoil](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@IrSoil](https://forums.unrealengine.com/u/IrSoil)\
**Post date:** [March 30, 2023, 2:26pm UTC](https://forums.unrealengine.com/t/weird-enhanced-input-problem-c-blueprint/832485/5 "2023-03-30T14:26:57Z")

</div>

> I have 3 options to solve this Problem:

those aren’t solutions, but only a workarounds. It isn’t the best way of solving problems.

Even if subscriptions are still active before widget get garbage collected despite you attempted to unsubscribe it doesn’t means you have to force\imitate gc, but you should unsubscribe properly.

Nevertheless, it’s up for you if workarounds is enough for your goals.

---

<div class="post-metadata">

**Author:** ![Scon81](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Scon81](https://forums.unrealengine.com/u/Scon81)\
**Post date:** [March 30, 2023, 4:31pm UTC](https://forums.unrealengine.com/t/weird-enhanced-input-problem-c-blueprint/832485/6 "2023-03-30T16:31:34Z")

</div>

That’s the way I do it in C++. I use Blueprints mainly for tests and prototyping 😉
