How to set up "Using Mouse Cursor For Aim"

4.9.1

Hi, im struggling to find a way to for the FirstPerson Template use the mouse input in conjunction with show mouse cursor. I have 3D widgets in my scene to click on and I want to have the mouse cursor always visible (a different texture obviously). Currently I have the cursor visible but I can only move the camera when I click on the viewport and drag.

So basically:

  • I want to set up a player controller where the pawn is rotated by the mouse input which has clickable events enabled and have a different texture for the mouse.

Hello Baserage,

If I’m understanding your issue correctly, it seems that you would like to have the mouse cursor visible on screen, but also be able to use the mouse to turn the character’s view as well. There is an answerhub post with a similar issue that gives an explanation of how to set this system up.
Have a look at the accepted answer: https://answers.unrealengine.com/questions/32550/showing-mouse-cursor-stops-input-from-mouse-axis.html
Hopefully that will give you an idea of what you need to do to get everything working.

Have a great day,

Sean Flint

I read the thread, the answers are really not what I want to achieve though. Isnt there just a way to use the default crosshair with click functions?

Hello Baserage,

Currently, there is a bug that causes 3D Widgets to be offset, UE-20071, which causes issues when trying to register click events. So your best bet is just to test your click events on another actor to ensure that they are working until that particular bug is resolved.

Are you looking to have the crosshair welded to the center of the screen? If not, I’ve figured out a way to achieve something similar to what you are trying to do. The first thing you need to do is set up a new player controller that enables click events. Ensure that you go to Edit->Project Settings → Maps and Modes → Default Modes → and set your player controller class to whatever you decide to call your new player controller. This new player controller should have Show Mouse Cursor and Enable Click Events enabled in the details panel. Also, you’ll have to ensure that you set Auto Receive Input under the Input section of the details panel for your Player Controller is set to Player 0. If this is set up correctly, you should see your new cursor on the screen and be able to move it around, but nothing will happen just yet.

Also, you’ll need to set up a Widget Blueprint for your Crosshair. Create a new widget blueprint, drag out an Image, and set the Size X and Size Y to 20. Expand the Brush panel and set the cursor as the texture you’d like to use. Also in the blueprint viewport, click the Fill Screen dropdown and select custom. Set this to 20 and 20 for the width and the height. Also, ensure that you anchor it to the center of the screen.

Now, go into the FirstPersonHUD blueprint and disconnect the Draw Texture node in the event graph, which will prevent the default crosshair from being shown. After this, go into your character blueprint and move the Mouse Input nodes(InputAxisTurn, InputAxisLookUp and the AddControllerYaw and AddControllerPitch). After you have these nodes moved a bit to the side to give yourself some space, set up your blueprint as I have mine. The TurnRate and LookUpDownRate variables were created by me, and are just simple float variables with default values of 0. Setting up your Look and Turn blueprints in this way will ensure that when the cursor reaches the edge of the screen, your character will rotate.

Give that a try and let me know how it works out, and if that is the result that you were looking to achieve. Hopefully that helps! Let me know if there are any areas that you need a bit more detail on, and I’ll be happy to provide.

Have a great day,

Sean Flint

Hello Baserage,

I am marking this topic as resolved, as I have not heard back from you in a few days. If there are any further questions, feel free to reply to this topic.

Have a great day,

Sean Flint

Hi Sean sorry for the late reply, just been on a short break. The blueprint works and thanks for showing me the photos. The problem I do have with this blueprint is how the mouse moves the camera. Is it possible for the mouse to be locked at the middle of the screen?

Hi Baserage,

If you look at the first-person template’s HUD blueprint, you’ll see how to draw the crosshair in the center of the screen. I’ll include a picture for your convenience. Then, you just have to disable the Show Mouse Cursor option in your player controller so that your cursor doesn’t show up in addition to the crosshair. Give that a shot and let me know how it works.

So I have reverted back to the default player controller set up where I can aim freely without pressing down the mouse button to look around. I have the hud setup and I have set Show Mouse Cursor to false. When I set Show Mouse Cursor to True I have to click and drag to look around, and the look isnt locked in the center like the hud texture is.

I just want the crosshair to have interaction with these widget buttons in screenspace.

It is so simple. “Have a default look around set up and be able to click on buttons”. I just havnt found any related ‘answered’ questions or articles on the matter.

The problem is that if you have the crosshair set in the center of the screen, it is just a texture and is not actually a cursor. In order to get your “click” events to fire from the center of the screen you’ll need to do a linetrace from the center of your screen on a Left Mouse Button event and then perform whatever action you want to perform on whichever object the line collides with. Have a look at the line trace documentation: https://docs.unrealengine.com/latest/INT/Gameplay/HowTo/UseRaycasts/Blueprints/index.html

So ive got a line trace set up, which finds the actors and its components correctly except for the widgets. Is there a way for the line trace to work on screen space widgets?

Unfortunately, the line trace will not work with screen space widgets. Screen space widgets exist on a different plane, so to speak, and thus cannot be affected by a line trace.

So… Can I still get help with this issue?

Someone has made it work here,

(0:34 onwards)

The functionality that is shown in the video is something that is added through a user-created plugin. For help with getting that set up, you’d have to get in contact with the person who created the plugin.