x

Search in
Sort by:

Question Status:

Search help

  • Simple searches use one or more words. Separate the words with spaces (cat dog) to search cat,dog or both. Separate the words with plus signs (cat +dog) to search for items that may contain cat but must contain dog.
  • You can further refine your search on the search results page, where you can search by keywords, author, topic. These can be combined with each other. Examples
    • cat dog --matches anything with cat,dog or both
    • cat +dog --searches for cat +dog where dog is a mandatory term
    • cat -dog -- searches for cat excluding any result containing dog
    • [cats] —will restrict your search to results with topic named "cats"
    • [cats] [dogs] —will restrict your search to results with both topics, "cats", and "dogs"

Mouse Cursor not changing until moved

I'm working on implementing dragging with a mouse. Here is the code that I am using to change the mouse cursor depending on the mouse button (in my PlayerController derived class):

 void AArenaGamePlayerController::OnMousePress()
 {
     CurrentMouseCursor = DragMouse;
 }

 void AArenaGamePlayerController::OnMouseReleased()
 {
     GEngine->AddOnScreenDebugMessage(-1, 10.f, FColor::Red, TEXT("PC OnMouseReleased ") );
     CurrentMouseCursor = NormalMouse;
 }

What I find is that when I hold the LMB down, the cursor changes as expected. However when I release the mouse button, and keep the pointer still, the cursor doesn't change. It only changes when I move it a pixel. I can see the debug message on the screen, so I 'm confident the code is being called. I have even tried moving the code into the PlayerTick method with exactly the same results.

Does anyone know how I can force the mouse cursor to update on screen?

Product Version: Not Selected
Tags:
more ▼

asked Aug 09 '14 at 09:22 AM in C++ Programming

avatar image

AusPaco
195 18 122 34

avatar image DrHobo Aug 19 '14 at 10:21 PM

I have the same problem.

avatar image hvfn May 23 '16 at 07:45 AM

This is still an issue in 4.11.2

avatar image inedible.red Dec 10 '18 at 02:36 PM

![alt text][1]

Hack for BP users : [1]: /storage/temp/261858-capture.png

capture.png (207.1 kB)
(comments are locked)
10|2000 characters needed characters left
Viewable by all users

5 answers: sort voted first

I think I know why, though I don't know how to fix it. :-(

We only set a value in the PlayerController's value structure without the aid of a function. That means that whatever is set can only be retrieved if a) another signal will pump a new message into the game's event queue and retrieve your value (hence the need for something to detect the new value and set a flag for the next round to react on this flag; or, b) the game queue is not finished yet and somewhere, something in the bottom of the engine will pick up the new value.

After tracing the whole message queue (yea, about a day or so), I found that neither events are happening. Our derived classes are very low in the food chain and nothing picks up the value we've set unless, like you mentioned, we create an additional event like moving the mouse which will get the new cursor value.

The culprit is located in UGameViewportClient::GetCursor() which is called by FSceneViewport::OnCursorQuery(); the cursor value it gets is earlier that anything we set on the game level. It retrieves the last value set prior to raising the mouse button and never comes back unless another signal is sent.

I've also noticed that when we keep the mouse button down, FSceneViewport::OnCursorQuery() is fired repetitively although a single message for LMB::IE_Pressed is sent in your application. I think the change between the normal arrow and the hand is delayed the same way, but because it is fired repetitively, the change occurs only the second time around, at 1/60th of a second.

The solution is that @Epic should provide some method to call when we change the cursor so that it triggers some flag that asks to re-read the cursor again, instead of simply letting us set a value. There maybe is one, but it's not clear in any documentation.

Regards.

more ▼

answered Aug 20 '14 at 04:18 PM

avatar image

DrHobo
276 32 37 54

avatar image StrangerGwenn Apr 18 '15 at 08:42 AM

This is also a problem when the game switches to cursor on and off. See : https://answers.unrealengine.com/questions/213389/mouse-focus-issues-when-hidingshowing-pointer.html

Any chance of a fix ?

(comments are locked)
10|2000 characters needed characters left
Viewable by all users

I had the same problem and found a hacky fix by simulating mouse movement.

I added a variable to my custom player controller:

  EMouseCursor::Type DesiredMouseCursor;

And added this code to the PlayerTick function:

     // UE4 Hack: The cursor change doesn't happen until the mouse is moved
     // As a workaround, simulate some mouse movement.
     // Make sure we only do this once per frame, otherwise we can create lots of
     // unnecessary pointer events which are more likely to cause noticeable mouse jitter.
     if (CurrentMouseCursor != DesiredMouseCursor)
     {
         CurrentMouseCursor = DesiredMouseCursor;
 
         auto& App = FSlateApplication::Get();
         FVector2D CursorPos = App.GetCursorPos();
         App.SetCursorPos(CursorPos + FVector2D(0, 1));
         App.OnMouseMove();
         App.SetCursorPos(CursorPos);
         App.OnMouseMove();
     }

Then to change the cursor I assign to DesiredMouseCursor instead of CurrentMouseCursor.

This is a dirty hack and has only been tested on Windows 7, but it might be useful to someone until there's an actual fix. From what I've read it looks like Linux requires a click rather than a move (and faking clicks could obviously cause some problems).

more ▼

answered Jun 09 '15 at 06:46 PM

avatar image

The Cheese
5 1 3

avatar image StrangerGwenn Jun 09 '15 at 08:12 PM

Unfortunately this doesn't work here on 4.8 preview, Windows 8.

Hiding the cursor through DesiredMouseCursor will still require a click to get mouse inputs, and Slate hover events will still require a click after showing the cursor. Same behavior as before.

FYI this was acknowledged to be a UE bug and is in the known bugs list for 4.8P4 - hopefully we get answers soon.

avatar image haimat Aug 13 '15 at 09:01 PM

It seems this is still an issue in 4.8.3, we experience the same problem in our project. Are there any updates on this issue?

avatar image joelr Nov 03 '15 at 12:08 AM

Still an issue in 4.9

(comments are locked)
10|2000 characters needed characters left
Viewable by all users

any updates on this? it is causing some issues for our project as well!

more ▼

answered May 12 '15 at 09:20 AM

avatar image

DragonHunt10
1 1 2 3

(comments are locked)
10|2000 characters needed characters left
Viewable by all users
  auto& App = FSlateApplication::Get();
          FVector2D CursorPos = App.GetCursorPos();
          App.SetCursorPos(CursorPos + FVector2D(0, 1));
          App.OnMouseMove();
          App.SetCursorPos(CursorPos);
          App.OnMouseMove();

Great work in 4.11.2. Thanks a lot!

more ▼

answered Jun 10 '16 at 04:25 AM

avatar image

SlashkoGaming
1 1 2 1

(comments are locked)
10|2000 characters needed characters left
Viewable by all users

Solution on 4.19.2 was

  auto& App = FSlateApplication::Get();
  App.QueryCursor(); //This line is refreshing the cursor (it executes fake mouse event for each platform).

more ▼

answered Apr 10 '19 at 12:20 AM

avatar image

ColdSteel48
537 6 19 23

(comments are locked)
10|2000 characters needed characters left
Viewable by all users

The problem is related to the focus.

I had the same problem when showing/hidding the cursor.

Try to put back the focus to the game viewport and the cursor should be reflected.

 // Sets back the focus to the game viewport
 FSlateApplication::Get().SetAllUserFocusToGameViewport();
more ▼

answered Jun 17 '19 at 03:57 PM

avatar image

domzorg
714 49 56 128

(comments are locked)
10|2000 characters needed characters left
Viewable by all users
Your answer
toggle preview:

Up to 5 attachments (including images) can be used with a maximum of 5.2 MB each and 5.2 MB total.

Follow this question

Once you sign in you will be able to subscribe for any updates here

Answers to this question