CurrentMouseCursor set in PlayerController is only used when a Mouse Button is held down

I have bShowMouseCursor set to true in my project, and the default one shows up just fine, so i wanted to change it depending on what object I’m hovering over. I implemented the logic for that in my player controller’s PlayerTick, using CurrentClickablePrimitive (bEnableMouseOverEvents is true for this variable to be valid), and I’ve confirmed that it sets CurrentMouseCursor on the PlayerController perfectly. However, I’m still getting the default mouse cursor when i hover over things, UNLESS I’m holding the left or mouse button down. Then my CurrentMouseCursor shows up.

Ive identified the culprit to be down to this in UGameViewportClient::GetCursor :

	if (!InViewport->HasMouseCapture() || !InViewport->HasFocus() || (ViewportConsole && ViewportConsole->ConsoleActive()))
	{
		return EMouseCursor::Default;
	}

So the viewport needs to have BOTH MouseCapture AND Focus for it’s cursor to show up. I’ve found it IMPOSSIBLE to get HasMouseCapture to return true UNLESS I’m actually holding a mouse button down (using the mouse capture interface doesn’t seem to affect it, neither does lock or setfocustoviewport and all the other functions i’ve found).

So i’ve changed that line to

if ((!InViewport->HasMouseCapture() && !InViewport->HasFocus()) || (ViewportConsole && ViewportConsole->ConsoleActive()))

Which means the viewport needs to have mouse capture or focus, doesn’t have to have both, and since it has focus, my set mouse cursor is respected.
Is this expected behaviour ? Maybe i should be using hit proxies to set my mouse cursor when i’m hovering over world stuff ? I have no idea how to use those and documentation is non-existent, however. Is there a way to have HasMouseCapture on my viewport return true (and this is a RTS, i DO NOT want my mouse to be locked to the window or not be able to leave it in windowed mode, the user should be able to multitask with normal apps just fine)

Hello ,

After looking into the issue, I believe that the mouse is working as intended. However, I have a blueprint that does what you have asked. Whenever the mouse is over an object in the scene it will change it’s “Current Mouse Cursor”. In this example whenever it is over a cube (BoxIsBox is the actor name) it will show as cross hairs. When ever it is over a sphere (sphereIsphere is the actor name) it will be a grabby hand. Finally whenever it is over none of these it will appear as the default cursor. This setup also allows the mouse to leave the window. I hope this helps.

My Character blueprint:

Note: This design could be improved by building in master classes so as to shorten the amount of “Branch” nodes that will need to be cycled through every frame.

Make it a great day

I get that, and that’s basically what my code is doing (setting CurrentMouseCursor in PlayerController). The issue is that if bShowMouseCursor is true on the defaults of PlayerController, CurrentMouseCusror in PlayerController never ends up getting used, because of that check i’ve shown.

Hello ,

I tried setting up the default for my player controller to set show mouse as true. I then disabled my “set show mouse cursor” node in my blueprints. The mouse appears to be updating as expected (changing from cross hair to hand to default). I am going to shoot an email and get him to try it out in code to see if there is a difference.

Hi ,

I did some testing with this issue today, and initially I had the same results that Rudy was seeing. When I took a closer look at the source code though, I realized that you were using 4.6 and we were testing in 4.5.1. When I ran the same test in 4.6, I saw what you were describing. I have entered a report about this issue to have it investigated further (UE-6348).

I am not too sure what you were referring to with regards to the mouse being captured in the viewport. When I was testing this issue, as well as the workaround that you mentioned, I was able to move the mouse outside of the viewport. The only time the mouse appeared to be captured was when I was holding down one of the mouse buttons.

Yes i just mentioned that i do not want the mouse captured.

No. The only reason i mentioned capturing is because the buggy condition for showing the correct mouse cursor is that it has to be captured.

It looks like a fix for this was implemented today. Once we have a stable internal build that contains the fix I’ll run through my tests again to make sure it is working as expected.

I also just wanted to make sure I am completely clear on the mouse capture issue. Are you actually seeing your mouse being captured in the viewport?

Ok. I didn’t see that happening when I was running tests using the workaround you provided. I’ll make sure to look for that when I can test the Engine again with the fix in place.

I’ve been having this exact problem since before 4.6 but I’m using blueprints entirely, no code at all. I hope that can help you narrow down what’s causing the problem because I can’t figure it out. It’s really frustrating. I only get the cursor change if a mouse button is being held.

If you don’t mind me asking, what is the workaround you’re mentioning? I’ve tried what’s listed in this post and I’m still having the same issue.

Hi Thokash,

had provided a workaround that involves a change to a line in the source code. If you are working in a binary version of the Engine installed by the Launcher, then you wouldn’t be able to make that change.

Have you tried the process that Rudy mentioned in his answer to this post?

That’s because you had the workaround on. I’m using it as well and it’s “fine” for me but i dont know if its correct for all situations.

Change the line in GameViewportClient.cpp

It doesn’t matter. They broke CurrentMouseCursor in 4.6 so it’s only used when the buttons are held down. Wait for fix or apply workaround.

Well in that case I won’t be able to make that change. And yeah, I already had something similar. Attached is a function I have that’s run off of eventTick. I’ve tried this, changing mouse cursor within each object (based off of cursorOverBegin/End events), and messing with the playerController defaults. Each has the same results. I get the expected cursor change ONLY if left/right click is held down. Otherwise it’s always the default mouse cursor.

I should add that other things that are driven by mouseOver events work well. Each of my units has a little selection decal underneath them that appears on mouseOver and disappears on mouseOverEnd. Those work fine. I have a blendable highlight on some units that work off of mouseOver and those work fine, too. The only thing that’s not working is cursor changing.

I’m doing kind of an RTS thing and at first you could switch between RTS and third person. Well when in TP you had no cursor. Upon switching over to RTS mode the cursor would appear and mouseOver-controlled cursor switching worked UNTIL I left/right clicked once. After that I got the problem we’ve been talking about. Also, maybe worth noting, when it was working, my mouse couldn’t leave the viewport. Once I clicked, it stopped working properly and my mouse could once again leave the viewport. Each time I’d switch from TP to RTS, it would work until that one click. I could repeat this as many times as I wanted. But obviously, you shouldn’t have to remove your cursor and show it every time you want a cursor switch to work. Although I haven’t tried doing that… I’ll try doing that and let you know how it works.

Well for me this problem has been going on since 4.4. It’s never worked for me.

Also looks like disabling then enabling the mouse cursor doesn’t work. Tried every combination of mouse/cursor options.

Hello Thokash,

I looked over the screen shot that you provided and was unable to gather enough information to provided any suggestions. Could you post a more complete picture of the blueprints that you are using?