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"

Office Holiday

Epic Games' offices will be on holiday from June 22nd to July 7th. During this period support will be limited. Our offices will reopen on Monday, July 8th. 

How could I Set mouse position via Blueprint?

Hi there!

I want to create WoW-like mouse look system. Hide mouse, disable mouse click events and rotate character while holding right mouse button. The problem is if I disable the mouse cursor it still move around. So when you press the right mouse button, the mouse disappears and you can rotate the camera. But when you release the right mouse button the mouse appears at a different location. There is one topic about that problem Link , but the solution is in c++ . Any suggestions how to solve this problem via Blueprint? (i found only "get mouse position" node)

Product Version: Not Selected
Tags:
more ▼

asked Apr 30 '14 at 07:15 AM in Blueprint Scripting

avatar image

kiyaha_jr
45 3 9 14

avatar image Dartanlla May 08 '14 at 04:34 PM

I am having the exact same issue. When the right-mouse button is clicked I am saving the mouse position to a var and hiding the mouse cursor. When the right-mouse button is released I am showing the mouse cursor again and I need to move the mouse position back to the location saved in the variable. I do not see anyway to do this in the blueprint. I am going to start searching the C++ code. I'll let you know what I find.

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

5 answers: sort voted first

I got it to work using a combination of Blueprints and C++ by doing the following:

I created a new C++ class called MyPlayerController to inherit from the default PlayerController class.

I added the following function to MyPlayerController using the code from your link above:

h File:

 UFUNCTION(BlueprintCallable, Category = "Game|Player")
 void SetMousePosition(float LocationX, float LocationY);

cpp File:

 void AMyPlayerController::SetMousePosition(float LocationX, float LocationY)
 {
     FViewport* v = CastChecked<ULocalPlayer>(this->Player)->ViewportClient->Viewport;
     int intX = (int)LocationX;
     int intY = (int)LocationY;
     v->SetMouse(intX, intY);
 }


Then I went back to my Controller blueprint and used File->Reparent Blueprint to change the parent class to MyPlayerController. Now my new function: SetMousePosition is available in the controller blueprint and I can finish my WoW-like mouse look functionality.

I have only be using UE4 for 3 days, but I have a feeling this might be the trick to getting a lot of stuff to work. Instead of using the default classes, create your own versions in C++ and then you can expose additional functionality to the blueprints :)

more ▼

answered May 08 '14 at 06:15 PM

avatar image

Dartanlla
2.6k 62 27 281

avatar image kiyaha_jr May 10 '14 at 07:08 PM

Its good when you know c++ =).Thanks for example , such mini tutorials kinda helps me understand how c++ works.

avatar image Miedie Nov 19 '15 at 12:56 AM

What if I want to set mouse cursor in the center of screen when my widget popup?

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

Hey,

What type of Blueprint are you attempting this in, try doing it in a Controller Blueprint.

You could do something like this:

alt text

There is probably other ways to do it, but this should get you started with some ideas.

-W

mycontroller.png (200.8 kB)
more ▼

answered Apr 30 '14 at 01:45 PM

avatar image

DizzyWes ♦♦ STAFF
5k 145 64 206

avatar image kiyaha_jr May 01 '14 at 09:27 AM

Thanks for detailed explanation. I have tested it before in controller blueprint.

And it looks almost the same as yours: alt text But it still doesn't solve the problem, maybe I've described situation not so good. In other words when mouse button is released I need to teleport/move mouse cursor in position where it was when mouse button was pressed. Press RMB->Rotate camera->Release RMB and got the same mouse cursor position.

dp_controller.jpg (289.0 kB)
(comments are locked)
10|2000 characters needed characters left
Viewable by all users

Dont think there is anyway in standard unreal at the moment but Rama have a node for it in his plugin.

~~~ ViewPort & Mouse Cursor ~~~

The Set/Get Mouse Position nodes work directly with the player's viewport, and do not require access to the HUD canvas.

~ Set Mouse Position - SET the mouse position to any values of your choosing!

~ Get Mouse Position - Get the current mouse position, will be consistent with results of SET Mouse Position

~ Get Center Of Viewport - Obtain the coordinates of the center of the viewport! Works in PIE as well as standalone game instances

For more info checkout the forum post about it https://forums.unrealengine.com/showthread.php?3851-(39)-Rama-s-Extra-Blueprint-Nodes-for-You-as-a-Plugin-No-C-Required!

more ▼

answered May 08 '14 at 04:49 PM

avatar image

Mullvaden
88 3 3 7

avatar image Shadowriver May 08 '14 at 05:04 PM

You can do that with standard C++ Unreal API from viewport classes, rama made them avable on blueprint :)

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

This code works as of UE4 4.13

 UFUNCTION(BlueprintCallable, Category = "Game|HUD", meta = (WorldContext = "WorldContextObject"))
 static void SetMousePosition(const UObject* WorldContextObject, int32 X, int32 Y);
 
 
 void UMyBlueprintLibrary::SetMousePosition(const UObject* WorldContextObject, int32 X, int32 Y)
 {
     UWorld* World = GEngine->GetWorldFromContextObject(WorldContextObject);
     APlayerController* PC = World->GetFirstPlayerController();
     if (!IsValid(PC))
     {
         return;
     }
 
     auto LP = Cast<ULocalPlayer>(PC->Player);
     if (!IsValid(LP))
     {
         return;
     }
 
     auto VP = LP->ViewportClient;
     if (!IsValid(VP))
     {
         return;
     }
 
     FSceneViewport* GVP = VP->GetGameViewport();
     if (GVP != nullptr)
     {
         GVP->SetMouse(X, Y);
     }
 }
 
 
 UFUNCTION(BlueprintCallable, Category = "Game|HUD", meta = (WorldContext = "WorldContextObject"))
 static void CenterMousePosition(const UObject* WorldContextObject);
 
 void UMyBlueprintLibrary::CenterMousePosition(const UObject* WorldContextObject)
 {
     UWorld* World = GEngine->GetWorldFromContextObject(WorldContextObject);
     APlayerController* PC = World->GetFirstPlayerController();
     if (!IsValid(PC))
     {
         return;
     }
 
     auto LP = Cast<ULocalPlayer>(PC->Player);
     if (!IsValid(LP))
     {
         return;
     }
 
     auto VP = LP->ViewportClient;
     if (!IsValid(VP))
     {
         return;
     }
 
     FSceneViewport* GVP = VP->GetGameViewport();
     if (GVP != nullptr)
     {
         const FIntPoint VPSize = GVP->GetSizeXY();
         GVP->SetMouse(VPSize.X /2, VPSize.Y / 2);
     }
 }
more ▼

answered Nov 05 '16 at 09:29 PM

avatar image

Kory
383 8 133 45

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

I found a way around this by SetMousePosition to the same position it's currently at.

This section of blueprint was run off of a Sequence after an EventTick node. Checking for player distance to the intractable object that the cursor is over. Hope this helps someone. :)

alt text

capture.jpg (110.8 kB)
more ▼

answered Nov 30 '18 at 06:25 AM

avatar image

DigitalCraze
6 1 2

(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