Lost control of Player Controller after Reparenting BP to C++

I have been tweaking with the controls of the default FlyingExampleMap and this has led me to parent a C++ file to my pawn Blueprint because I want to be able to SetMousePosition, which is impossible with Blueprints alone.

I successfully parented C++ file with the function “SetMousePosition” to my BP but now whenever I start my game the camera starts in the middle of nowhere and I am unable to control the UFO. I even see my UFO fly lifelessly into the wall!

My two C++ files I used for parenting are as follows:

MyPlayerController7.cpp

// Fill out your copyright notice in the Description page of Project Settings.

#include "MyPlayerController7.h"
#include "Fly1.h"


void AMyPlayerController7::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);
}

MyPlayerController7.h

// Fill out your copyright notice in the Description page of Project Settings.

#pragma once

#include "CoreMinimal.h"
#include "GameFramework/PlayerController.h"
#include "MyPlayerController7.generated.h"

/**
 * 
 */
UCLASS()
class FLY1_API AMyPlayerController7 : public APlayerController
{
	GENERATED_BODY()
	
		UFUNCTION(BlueprintCallable, Category = "Game|Player")
		void SetMousePosition(float LocationX, float LocationY);
	
	
};

I want to be able to hold down a button and Pitch and Yaw the ship without having to continuously drag the mouse and pick it up again over and over. ‘Get Mouse X’ and ‘Get Mouse Y’ does not work in this regard and ‘Get Mouse Position’ is unreliable as well. I learned how to parent a C++ file to my Blueprint so that I can set the mouse location in order to facilitate this programming need so that if a button is held, the mouse can function to steer the ship more similarly to holding a joystick to one side or another.

I have been using blueprint for a while but have never had to dive into C++ until today. I also found my code from another on this forum so it may be outdated? Can anyone help me out please? Thanks.

This sounbds like pawn possession issue, the player controller don’t posses the UFO so something tells me the configuration is the issue, please describe how you spawning and if you useing Default Pawn settings?

the code it self looks ok to me, or else you override some function PlayerController should behave the same way. If override function you should use Super::FunctionName() in the function code or else you will block (or else you really want to do that) parent class code which might lead to situation like you describe, but again your code is fine as you don’t override anything. For example if you don’t call super on BeginPlay or Tick overrides the blueprint nodes for those events won’t work as those functions call them in AActor class code.

Thank you for your reply ! However I have abandoned my attempt at implementing C++ into my Blueprint project as I have found a much simpler solution that does not require C++ or 's BP Library.

I wanted to track the mouse in a circle shaped boundary similar to how input would appear from a joystick or a thumb stick on a controller in order to have a Flying object automatically Pitch and Yaw without me have to drag the mouse and pick it up on my mouse pad over and over. When the right mouse button is held and you move your mouse up and hold it on the north side of your mouse pad, the FlyingPawn will constantly loop over and over without you having to move the mouse again.

Edit > Project Settings > Input > Mouse Properties > Enable Mouse Smoothing = OFF :slight_smile: