appropriately channeling mouse input between level, ui, player controller

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

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.

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

  • the interface:

  • implementation in the base class:

  • overriding in derived:

  • input processing and calling in the controller:


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 :warning: )

All of this is just an example.

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

1 Like

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?

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.

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

what do you mean by interface

https://www.youtube.com/results?search_query=ue5+interface

Or #7:

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

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:

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

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

Equip the interface with an enumerator like in the example:

image

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.

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

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