# appropriately channeling mouse input between level, ui, player controller

**URL:** <https://forums.unrealengine.com/t/appropriately-channeling-mouse-input-between-level-ui-player-controller/1890409>\
**Category:** Programming & Scripting\
**Tags:** unreal-engine, question\
**Created:** [June 5, 2024, 7:23am UTC](https://forums.unrealengine.com/t/appropriately-channeling-mouse-input-between-level-ui-player-controller/1890409 "2024-06-05T07:23:48Z")\
**Posts on this page:** 13\
**Page:** 1

<div class="post-metadata">

**Author:** ![barbrian0723](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@barbrian0723](https://forums.unrealengine.com/u/barbrian0723)\
**Post date:** [June 5, 2024, 7:23am UTC](https://forums.unrealengine.com/t/appropriately-channeling-mouse-input-between-level-ui-player-controller/1890409/1 "2024-06-05T07:23:49Z")

</div>

hi  
i am trying to sort out mouse click events  
i have (created) appropriate input actions  
i have multiple input mappings to prioritize these  
in my (topdown) player controller, i have thus far 2 input mappings at different priorities  
the first input mapping is to channel mouse clicks to the user interface (ui) / hud  
the 2nd lower priority input mapping is to keep the default top down character movement with / based on mouse clicks

now i want to also enable mouse clicks in the level. clicking on objects of interest etc  
how do i go about this now?  
what i can think of is i suppose i must create another input map, set it high(est) priority and activate it somewhere (put it in a blueprint)  
but i want to work off events in a blueprint associated with the object in the level of interest that is clicked  
ie, for the object in the level that is clicked / clickable, i want to utilize the event in the object’s blueprint  
at this point simply using the on clicked event is not working because i have confirmed that the mouse click is consumed by the ui  
regards

---

<div class="post-metadata">

**Author:** ![Everynone](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/everynone/32/1135017_2.png) [@Everynone](https://forums.unrealengine.com/u/Everynone)\
**Post date:** [June 5, 2024, 7:52am UTC](https://forums.unrealengine.com/t/appropriately-channeling-mouse-input-between-level-ui-player-controller/1890409/2 "2024-06-05T07:52:50Z")

</div>

> [@barbrian0723](#):
>
> ie, for the object in the level that is clicked / clickable, i want to utilize the event in the object’s blueprint

Click in the PC → trace → send Hit Actor an `Interface Message`.

- this way you can even add data to the click, how long it was, how fast we double clicked and so on, and let the target interpret it.
- interfaces can the inherited - derived classes can add their own granular interpretations
- you get to keep most (if not all) input handling in just a few classes (PC / Pawn / main UI)
- interface functions can, optionally, return data; you’d get a response from the target regarding how the click was processed

> but i want to work off events

You’re at a point where the mundane `onClicked` may simply be insufficient and too rigid for you needs.

---

<div class="post-metadata">

**Author:** ![barbrian0723](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@barbrian0723](https://forums.unrealengine.com/u/barbrian0723)\
**Post date:** [June 5, 2024, 8:16am UTC](https://forums.unrealengine.com/t/appropriately-channeling-mouse-input-between-level-ui-player-controller/1890409/3 "2024-06-05T08:16:02Z")

</div>

thanks

i am trying to interpret PC \> trace \> send hit actor interface message

i suppose you are not talking about doing a line trace or box trace etc (ordinary collision trAce), but obtaining a “system” or internal trace result and reading / interpreting / utilizing that  
something like tracequery or “get default click trace channel” (the latter more readily useable)

can you perhaps provide an example even if it is only elementary / rudimentary  
or give the function node to use that will work as well

---

<div class="post-metadata">

**Author:** ![Everynone](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/everynone/32/1135017_2.png) [@Everynone](https://forums.unrealengine.com/u/Everynone)\
**Post date:** [June 5, 2024, 8:20am UTC](https://forums.unrealengine.com/t/appropriately-channeling-mouse-input-between-level-ui-player-controller/1890409/4 "2024-06-05T08:20:59Z")

</div>

- the interface:

 ![image](https://d3kjluh73b9h9o.cloudfront.net/original/4X/d/d/3/dd3c2132d96630b9a688a3ec76a7b0f3da69cd1e.png)

- implementation in the base class:

 ![image](https://d3kjluh73b9h9o.cloudfront.net/original/4X/5/6/d/56d308cd8ac325e4cab3edc0ff70bfd7f97d8aae.png)

- overriding in derived:

 ![image](https://d3kjluh73b9h9o.cloudfront.net/original/4X/1/9/d/19d37dcb8e8283956f1deee20fe23528c46e3900.png)

- input processing and calling in the controller:

 ![image](https://d3kjluh73b9h9o.cloudfront.net/original/4X/9/1/7/9172670abdf5604e09e68b14964a2361ff1994e7.png)

* * *

In short:

- handle the Enhanced Input in the player controller
- send generic requests to whoever needs it
- you can use regular tracing instead, ofc
- if you send a message to something that does not have and interface, nothing happens (but default data **will** be returned ⚠ )

* * *

All of this is just an example.

---

<div class="post-metadata">

**Author:** ![barbrian0723](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@barbrian0723](https://forums.unrealengine.com/u/barbrian0723)\
**Post date:** [June 5, 2024, 8:25am UTC](https://forums.unrealengine.com/t/appropriately-channeling-mouse-input-between-level-ui-player-controller/1890409/5 "2024-06-05T08:25:28Z")

</div>

ok you have given me enough to work with  
let me see what i can do

---

<div class="post-metadata">

**Author:** ![barbrian0723](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@barbrian0723](https://forums.unrealengine.com/u/barbrian0723)\
**Post date:** [June 5, 2024, 9:34am UTC](https://forums.unrealengine.com/t/appropriately-channeling-mouse-input-between-level-ui-player-controller/1890409/6 "2024-06-05T09:34:23Z")

</div>

great i was able to get somewhere with /get hit result under cursor for objects/  
i took the hit result of the above and searched it against an array of clickable objects to see whether a clickable object was clicked  
i did this in my hud widget as the hud has greater priority ito the mouse than the PC  
how will i now pass a mouse click event not consumed / of interest to the HUD / level to the player controller blueprint and have it register as an event?  
can i create a custom event for the PC or must i set a variable the PC can test and reset per tick?

---

<div class="post-metadata">

**Author:** ![Everynone](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/everynone/32/1135017_2.png) [@Everynone](https://forums.unrealengine.com/u/Everynone)\
**Post date:** [June 5, 2024, 10:18am UTC](https://forums.unrealengine.com/t/appropriately-channeling-mouse-input-between-level-ui-player-controller/1890409/7 "2024-06-05T10:18:46Z")

</div>

> [@barbrian0723](#):
>
> i took the hit result of the above and searched it against an array of clickable objects to see whether a clickable object was clicked

If you used an interface as suggested, you would not need to do any of this. It’s not scalable. Send the message, if the actor does not have an interface, nothing happens.

> i did this in my hud widget as the hud has greater priority ito the mouse than the PC

Avoid scripting game logic inside the UI. The job of the UI is to show results, not process them.

> how will i now pass a mouse click event not consumed / of interest to the HUD / level to the player controller blueprint and have it register as an event?

EI consumes input based on the mapping context priority. Again, if you used an interface, you’d get feedback from the clicked actor.

> can i create a custom event for the PC or must i set a variable the PC can test and reset per tick?

Not sure what’s it means and what the intent is.

---

<div class="post-metadata">

**Author:** ![barbrian0723](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@barbrian0723](https://forums.unrealengine.com/u/barbrian0723)\
**Post date:** [June 5, 2024, 10:42am UTC](https://forums.unrealengine.com/t/appropriately-channeling-mouse-input-between-level-ui-player-controller/1890409/8 "2024-06-05T10:42:58Z")

</div>

what do you mean by interface. or, how do i create an interface

i am currently working mostly in the hud, as i looked at gamemode and gamestate and did not see the need or urgency at this point to create a custom gamemode or gamestate

perhaps the urgency is in the way the hud is treated as opposed to the gamestate at least

from what you sent me and what i got out of it is that you are breaking down the mouse input and processing it in the pc via get hit result under cursor  
that i have now done. just in my hud  
if i do this in the pc i need to pass (some of) it to the hud for the ui to process  
if i do it in the hud, i need to pass the stuff the ui is not using and intended for the pc to the pc  
maybe i am still missing your suggestion on the best way to pass, and it being an interface or something related

would it be better for me to put my stuff in the pc then if i do not yet prefer a gamestate?

thanks

---

<div class="post-metadata">

**Author:** ![Everynone](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/everynone/32/1135017_2.png) [@Everynone](https://forums.unrealengine.com/u/Everynone)\
**Post date:** [June 5, 2024, 10:53am UTC](https://forums.unrealengine.com/t/appropriately-channeling-mouse-input-between-level-ui-player-controller/1890409/9 "2024-06-05T10:53:31Z")

</div>

> what do you mean by interface

[https://www.youtube.com/results?search\_query=ue5+interface](https://www.youtube.com/results?search_query=ue5+interface)

Or #7:

> **[Blueprint Communication | Course](https://dev.epicgames.com/community/learning/courses/LWv/unreal-engine-blueprint-communication/ypKl/unreal-engine-blueprint-communication-overview)**
>
> In this course from the Epic Online Learning Team, create more efficient projects by dividing and organizing your Blueprints by functionality. Let’s exa...

Or what I described in the previous posts, I’ve provided tangible working examples of re-routing input via messages that does not muddle the water by implementing EI in actors / widgets. Considering that the PC and the HUD class are _very close_ friends:

 ![image](https://d3kjluh73b9h9o.cloudfront.net/original/4X/f/e/d/fedba62c92046337551a43e40170ce58302a0c31.png)

You could treat it as an UI _hub_ for comms, using this legacy class can often trivialise it.

* * *

Interface is an agnostic communication method, and one of the big three:

- direct comms
- event dispatchers
- interfaces

* * *

> if i do this in the pc i need to pass (some of) it to the hud for the ui to process  
> if i do it in the hud, i need to pass the stuff the ui is not using and intended for the pc to the pc

There is a class **designed** for input processing, the will of the player - the Player Controller. Why fight the system? However, it’s your game, your script. It’s an unorthodox approach, though. Take my advice or leave it, ofc.

With the advent of the EI, you can implement input directly in widgets, actor components and more. However, you then must control the priority and consumption yourself. Here’s another example, focusing on consumption specifically:

> [@"Consume input" doesn't work (the input still propagates everywhere)](https://forums.unrealengine.com/t/consume-input-doesnt-work-the-input-still-propagates-everywhere/1213316/4):
>
> Imagine I have 2 sets of controls: IMC\_Default (Priority 0) to move around with WASD IMC\_Backpack (Priority 1) to move between backpack slots, also with WASD if priorities are equal, the one added last gets to the hardware input first When I open my backpack and WASD inside it, I’d rather not walk off the cliff, so I add a new Mapping Context with higher priority, so it can intercept Actions associated with keys: Think with mapping contexts - abstracted layers of input. I…

Not sure if this helps or if that’s what you’re after.

---

<div class="post-metadata">

**Author:** ![barbrian0723](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@barbrian0723](https://forums.unrealengine.com/u/barbrian0723)\
**Post date:** [June 5, 2024, 1:38pm UTC](https://forums.unrealengine.com/t/appropriately-channeling-mouse-input-between-level-ui-player-controller/1890409/10 "2024-06-05T13:38:26Z")

</div>

helpful  
thanks  
managed to do this with get hit result under cursor and now managed to clean everything up with blueprint interfaces  
although the pc move character on mouse click utilizes 4 sub events to do so (start , triggered, cancelled, completed)  
but that is not the end of the world

---

<div class="post-metadata">

**Author:** ![Everynone](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/everynone/32/1135017_2.png) [@Everynone](https://forums.unrealengine.com/u/Everynone)\
**Post date:** [June 5, 2024, 1:43pm UTC](https://forums.unrealengine.com/t/appropriately-channeling-mouse-input-between-level-ui-player-controller/1890409/11 "2024-06-05T13:43:01Z")

</div>

> [@barbrian0723](#):
>
> the pc move character on mouse click utilizes 4 sub events to do so (start , triggered, cancelled, completed)

Equip the interface with an enumerator like in the example:

![image](https://d3kjluh73b9h9o.cloudfront.net/original/4X/4/4/5/44500124ea4c72f0d076888308d4902eff379648.png)

Instead of mouse buttons, send `start, triggered, cancelled, completed` states. Not entirely sure how it’s all supposed to work but toy with those ideas.

---

<div class="post-metadata">

**Author:** ![barbrian0723](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@barbrian0723](https://forums.unrealengine.com/u/barbrian0723)\
**Post date:** [June 5, 2024, 1:55pm UTC](https://forums.unrealengine.com/t/appropriately-channeling-mouse-input-between-level-ui-player-controller/1890409/12 "2024-06-05T13:55:26Z")

</div>

yes i have sent the event type as an integer input of the interface message  
but you can do the character move with mouse with just 1 event if you take the pc blueprint nodes and sequence them after each other

---

<div class="post-metadata">

**Author:** ![system](https://d3kjluh73b9h9o.cloudfront.net/original/4X/7/1/3/713c9d3f58553f0de89543d76a8a3a2779dc9fa4.png) [@system](https://forums.unrealengine.com/u/system)\
**Post date:** [July 5, 2024, 1:55pm UTC](https://forums.unrealengine.com/t/appropriately-channeling-mouse-input-between-level-ui-player-controller/1890409/13 "2024-07-05T13:55:59Z")

</div>

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