Hi Everyone,
Im new to the unreal engine but have a background in software development as my day job. Im following one of thee unreal tutorials on character creation and movement. However I have come across an issue that I cant resolve. I created my character in a C++ class and then created a blueprint from it, the blueprint is now being used as my default pawn class in project settings. I have a static mesh for my character and have in C++ created a first person camera component and attached it to the player capsule, this is working and I can see the camera when opening the blueprint. However after I change the value in C++ for the camera location (from 50.0f to 100.0f for example) and then hit compile, this change is not reflected in the editor. Also im calling GetMesh()->SetOwnerNoSee(true); in the character constructor, which I thought should stop me seeing it in first person but yet it persists in the editor. Any ideas would be greatly appreciated, code below for reference.
TestCharacter.h
#pragma once
#include "CoreMinimal.h"
#include "GameFramework/Character.h"
#include "Camera/CameraComponent.h"
#include "TestCharacter.generated.h"
UCLASS()
class LEARNING_API ATestCharacter : public ACharacter
{
GENERATED_BODY()
public:
// Sets default values for this character's properties
ATestCharacter();
protected:
// Called when the game starts or when spawned
virtual void BeginPlay() override;
public:
// Called every frame
virtual void Tick(float DeltaTime) override;
// Called to bind functionality to input
virtual void SetupPlayerInputComponent(class UInputComponent* PlayerInputComponent) override;
// Handles input for moving forward and backward.
UFUNCTION()
void MoveForward(float Value);
// Handles input for moving right and left.
UFUNCTION()
void MoveRight(float Value);
UFUNCTION()
void StartJump();
UFUNCTION()
void StopJump();
UPROPERTY()
UCameraComponent* FPSCameraComponent;
};
TestCharacter.cpp
// Fill out your copyright notice in the Description page of Project Settings.
#include "TestCharacter.h"
#include "Components/CapsuleComponent.h"
#include "Engine/Engine.h"
#include "Components/StaticMeshComponent.h"
// Sets default values
ATestCharacter::ATestCharacter()
{
// Set this character to call Tick() every frame. You can turn this off to improve performance if you don't need it.
PrimaryActorTick.bCanEverTick = true;
//Create First Person Camera Component
FPSCameraComponent = CreateDefaultSubobject<UCameraComponent>(TEXT("FirstPersonCamera"));
//Now attach the camera to the player capsule/sphere
FPSCameraComponent->SetupAttachment(GetCapsuleComponent());
// Position the camera slightly above the eyes.
FPSCameraComponent->SetRelativeLocation(FVector(0.0f, 0.0f, 50.0f + BaseEyeHeight));
// Allow the pawn to control camera rotation.
FPSCameraComponent->bUsePawnControlRotation = true;
GetMesh()->SetOwnerNoSee(true);
}
// Called when the game starts or when spawned
void ATestCharacter::BeginPlay()
{
Super::BeginPlay();
if (GEngine) {
GEngine->AddOnScreenDebugMessage(-1, 1.0f, FColor::Red, TEXT("Test"));
}
}
// Called every frame
void ATestCharacter::Tick(float DeltaTime)
{
Super::Tick(DeltaTime);
}
// Called to bind functionality to input
void ATestCharacter::SetupPlayerInputComponent(UInputComponent* PlayerInputComponent)
{
Super::SetupPlayerInputComponent(PlayerInputComponent);
//Player Axis Movements
PlayerInputComponent->BindAxis("MoveForward", this, &ATestCharacter::MoveForward);
PlayerInputComponent->BindAxis("MoveRight", this, &ATestCharacter::MoveRight);
PlayerInputComponent->BindAxis("LookUp", this, &ATestCharacter::AddControllerPitchInput);
PlayerInputComponent->BindAxis("Turn", this, &ATestCharacter::AddControllerYawInput);
//Player Action Control Bindings
PlayerInputComponent->BindAction("Jump", IE_Pressed, this, &ATestCharacter::StartJump);
PlayerInputComponent->BindAction("Jump", IE_Released, this, &ATestCharacter::StopJump);
}
void ATestCharacter::MoveForward(float Value)
{
// Find out which way is "forward" and record that the player wants to move that way.
FVector Direction = FRotationMatrix(Controller->GetControlRotation()).GetScaledAxis(EAxis::X);
AddMovementInput(Direction, Value);
}
void ATestCharacter::MoveRight(float Value)
{
FVector Direction = FRotationMatrix(Controller->GetControlRotation()).GetScaledAxis(EAxis::Y);
AddMovementInput(Direction, Value);
}
void ATestCharacter::StartJump()
{
bPressedJump = true;
}
void ATestCharacter::StopJump()
{
bPressedJump = false;
}