How can I tell my blueprint to react in a particular way when my cursor is located within a specific part of the screen?


ok, acutally i have a few more questions, but let’s start with the mouse cursor.

What i’m trying to do is, to tell my mouse which gun should be fired by clicking the LMB, depending on the cursor position.
For example:

I have 3 guns placed in a row at the bottom of my screen:
One on the left, in the middle and one on the right.

When the cursor is more on the left side of the screen, the gun on the left should be fired, if its more in the middle, the gun in the middle should be fired and so on.

I know there is a node “getViewportSize” and “getMousePosition”.
But i’m not really sure, how to start…

Let’s say ViewportSize is X 1920 and Y 1080.
I have to divide X with 3 and compare it.
If it’s < than 640, fire “gun left”, if it’s > than 640 but < than 1280 fire “gun middle” and if it’s > 1280 fire “gun right”.
But the problems with these numbers are, what if the screen size changes, depending on the the players screen resolution or mobile he is using.

  1. How can i tell my blueprint to react, when my mouse is in a specific part of my screen?
  2. And is this something i should do in the level blueprint or in my Gun-Blueprint?
  3. Do i need three different Blueprints for each gun or can i do this with one gun-blueprint?

I know it’s a lot and very complicated, but i hope someone can help me with it.
Thanks in advance!



Well, this is more or less what you want to do
If you want it to check regardless if you click, you have to put the left mouse event into the tick event
What this BP does:
Saves screen size in the begin play. When Left mouse is clicked, divides screen size by 3 and checks in which of the 3 fractions of the screen the mouse is positioned.
Obviously you have to swap my “guns” with your own :wink:

Good luck!

Thank you! This was really helpful and it’s working with a few changes. I had to set the Mouse Position as the input instead of the Viewport Size.
The Mouse position increases from left to the right and with the ViewportSize as the input, i strangely couldn’t get the Middle Gun to work.
But it’s working now, thanks again!!