Hey Albert, I recently had to do this as well. This isn’t perfect but it should get you on the right direction.
I used Rama’s code for setting the cursor position in blueprints. (As a disclaimer I don’t know C++ so this is sort of hobbled together)
Go to file Add Code to Project.
Create a new class from PlayerController and call it NewPlayerController
in the .h file:
#pragma once
#include "Kismet/BlueprintFunctionLibrary.h"
#include "GameFramework/PlayerController.h"
#include "MyNewPlayerController.generated.h"
/**
*
*/
UCLASS()
class YOURPROJECT_API AMyNewPlayerController : public APlayerController
{
GENERATED_UCLASS_BODY()
public:
UFUNCTION(BlueprintCallable, Category = "YOURCATEGORY")
static bool Viewport__SetMousePosition(const APlayerController* ThePC, const float& PosX, const float& PosY);
};
In the .cpp file:
#include "YOURPROJECT.h"
#include "MyNewPlayerController.h"
AMyNewPlayerController::AMyNewPlayerController(const class FPostConstructInitializeProperties& PCIP)
: Super(PCIP)
{
}
bool AMyNewPlayerController::Viewport__SetMousePosition(const APlayerController* ThePC, const float& PosX, const float& PosY)
{
if (!ThePC) return false;
//~~~~~~~~~~~~~
//Get Player
const ULocalPlayer * VictoryPlayer = Cast<ULocalPlayer>(ThePC->Player);
//PlayerController::Player is UPlayer
if (!VictoryPlayer) return false;
//~~~~~~~~~~~~~~~~~~~~
//get view port ptr
const UGameViewportClient * VictoryViewportClient =
Cast < UGameViewportClient >(VictoryPlayer->ViewportClient);
if (!VictoryViewportClient) return false;
//~~~~~~~~~~~~~~~~~~~~
FViewport * VictoryViewport = VictoryViewportClient->Viewport;
if (!VictoryViewport) return false;
//~~~~~~~~~~~~~~~~~~~~
//Set Mouse
VictoryViewport->SetMouse(int32(PosX), int32(PosY));
return true;
}
After rebuilding, open your playercontroller blueprint and reparent it to your new playercontroller.
Right click, and enter “Set mouse” and you should see the new node you created, under whatever category you entered in the .h file.
This is my playercontroller, controlling the cursor with the D pad: