Is this a good and efficient First Person camera implementation?

Hi Guys, I’ve written a c++ code for a First Person camera, based on the UE4 templates and the First Person Shooter tutorial found on the wiki page. Here’s what I’ve got:

.h

GENERATED_UCLASS_BODY()

	UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = Camera)
	TSubobjectPtr<class UCameraComponent>MainCamera;

	UPROPERTY(VisibleDefaultsOnly, Category = Mesh)
	TSubobjectPtr<USkeletalMeshComponent>FPChar;

	bool bIsHeroCrouched;

protected:
	void MoveForward(float value);
	void MoveRight(float value);
	void CrouchHero();
	void Tick(float DeltaTime);
	void SetupPlayerInputComponent(UInputComponent *InputComponent);

.cpp:

AUECharHero::AUECharHero(const class FPostConstructInitializeProperties& PCIP)
	: Super(PCIP)
{
	//Inicializa el tamaño del CapsuleComponent para el personaje, creo que tiene que ver con las físicas..?
	CapsuleComponent->InitCapsuleSize(46.0f, 96.0f);

	bIsHeroCrouched = false;
	
	//Usar el pitch, yaw y rooll del control en el control del personaje.
	bUseControllerRotationPitch = true;
	bUseControllerRotationRoll = true;
	bUseControllerRotationYaw = true;

	//Cración de la cámara
	MainCamera = PCIP.CreateDefaultSubobject<UCameraComponent>(this, TEXT("CharCamera"));
	MainCamera->AttachParent = CapsuleComponent;//Con eso se atacha al Capsule conponent cono un Child.
	MainCamera->RelativeLocation = FVector(0.0f, 0.0f, 10.0f + BaseEyeHeight);//Se fija la posición de la camara

	//Se crea para el personaje en primera persona
	FPChar = PCIP.CreateDefaultSubobject<USkeletalMeshComponent>(this, TEXT("FPChar"));
	FPChar->SetOnlyOwnerSee(true);         //solo el que juega va a verlo, los demás verían el personaje completo
	FPChar->AttachParent = MainCamera;     //se atacha a la cámara 
	FPChar->bCastDynamicShadow = false;    //No crea sombras
	FPChar->CastShadow = false;
	Mesh->SetOwnerNoSee(true);

	//CharacterMovement->bOrientRotationToMovement = false;

}


void AUECharHero::SetupPlayerInputComponent(UInputComponent *InputComponent)
{
	check(InputComponent);
	InputComponent->BindAxis("MoveForward", this, &AUECharHero::MoveForward);
	InputComponent->BindAxis("MoveRight", this, &AUECharHero::MoveRight);
	InputComponent->BindAction("Jump", IE_Pressed, this, &ACharacter::Jump);
	InputComponent->BindAxis("Turn", this, &ACharacter::AddControllerYawInput);
	InputComponent->BindAxis("LookUp", this, &ACharacter::AddControllerPitchInput);
	InputComponent->BindAction("Crouch", IE_Pressed, this, &AUECharHero::CrouchHero);
}



void AUECharHero::MoveRight(float value)
{
	if (Controller!=NULL && value != 0.0f)
	{
		const FRotator Rotation = Controller->GetControlRotation();
		const FRotator YawRotation(0, Rotation.Yaw, 0);

		// get right vector 
		const FVector Direction = FRotationMatrix(YawRotation).GetUnitAxis(EAxis::Y);
		// add movement in that direction
		if (!bIsHeroCrouched)
		{
			AddMovementInput(Direction, value);
		}
		else
		{
			AddMovementInput(Direction, value/2.0f);
		}
	}
}

void AUECharHero::Tick(float DeltaTime)
{
	FRotator Rotacion = Controller->GetControlRotation();
	FString Message;
	Message = Rotacion.ToString();
	if (GEngine)
	{
		GEngine->AddOnScreenDebugMessage(1, 1.0f, FColor::Blue, Message);
	}

	if (bIsHeroCrouched)
	{
		GEngine->AddOnScreenDebugMessage(2, 1.0f, FColor::Cyan, TEXT("Is Crouched"));
	}

}

void AUECharHero::MoveForward(float value)
{
	if (Controller !=NULL && value != 0.0f)
	{
		const FRotator Rotation = Controller->GetControlRotation();
		const FRotator YawRotation(0, Rotation.Yaw, 0);

		// get forward vector
		const FVector Direction = FRotationMatrix(YawRotation).GetUnitAxis(EAxis::X);
		if (!bIsHeroCrouched)
		{
			AddMovementInput(Direction, value);
		}
		else
		{
			AddMovementInput(Direction, value/2.0f);
		}
		
	}
	
}

void AUECharHero::CrouchHero()
{
	if (Controller != NULL)
	{
		if (!bIsHeroCrouched)
		{
			bIsHeroCrouched = true;
		}
		else
		{
			bIsHeroCrouched = false;
		}
	}
}

As I`m relatively new writing code in C++, i wanna know ¿is it efficient?, ¿Is there a better way to implement it?, Any comment on the code will be really appreciated.

Thanks!!

Doing a quick view and being a novice on UE 4, looks that there is nothing strange that could be inefficient.
But I see a error. On void AUECharHero::Tick (line 71), you have this code :

    if (GEngine)
    {
       GEngine->AddOnScreenDebugMessage(1, 1.0f, FColor::Blue, Message);
    }
 
    if (bIsHeroCrouched)
    {
       GEngine->AddOnScreenDebugMessage(2, 1.0f, FColor::Cyan, TEXT("Is Crouched"));
    }

You are checking that GEngine isn’t a nullptr before calling it to show “Message” variable, but you forgot to conver the second call to GEngine. Should be :

   if (GEngine)
   {
       GEngine->AddOnScreenDebugMessage(1, 1.0f, FColor::Blue, Message);

       if (bIsHeroCrouched)
       {
          GEngine->AddOnScreenDebugMessage(2, 1.0f, FColor::Cyan, TEXT("Is Crouched"));
       }
   }

Also, before posting on a English place, you should put your comments in english. Not all people here are spanish native like you and me.

yes, you’re right, I’ve should include the second IF INSIDE the GEngine IF, an honest mistake, and again, you’re right about the comments, I’ve totally forgot about them. Thanks for your answer!! (Y)