Changing UPROPERTY does not seem to affect Camera placement

Okay. You were correct that the GetCapsuleComponent() method is not a method of APawn. I replaced it with GetRootComponent() (after setting the RootComponent value to the mesh,) and now Unreal Engine crashes on startup because it does not like the DetachFromComponent call.

AEaglePawn::AEaglePawn()
{
 	// Set this pawn to call Tick() every frame.  You can turn this off to improve performance if you don't need it.
	PrimaryActorTick.bCanEverTick = true;
	
	//Get a reference to the game world so we can spawn new objects as needed
	UWorld* World = GetWorld();
	if (World) {
		FActorSpawnParameters SpawnParams;
		SpawnParams.Owner = this;
		SpawnParams.Instigator = GetInstigator();
		//Create an obstacle spawner. Its state will depend on the player's state (pause, ready, etc)
		Spawner = World->SpawnActor<AObstacleSpawner>(SpawnParams);
	}
	
	//Create a first-person mesh component for the owning player.
	PlayerMesh = CreateDefaultSubobject<USkeletalMeshComponent>(TEXT("PlayerMesh"));
	check(PlayerMesh != nullptr);

	//Assign the mesh as the root component of the player object
	RootComponent = PlayerMesh;

	//Create a third person camera component
	ThirdPersonCameraComponent = CreateDefaultSubobject<UCameraComponent>(TEXT("ThirdPersonCamera"));
	check(ThirdPersonCameraComponent != nullptr);

	//Attach the camera so you can set its relative location and rotation
	ThirdPersonCameraComponent->SetupAttachment(GetRootComponent());

	//Position the camera about 5 meters away from the bird, sideways
	ThirdPersonCameraComponent->SetRelativeLocation(FVector(CAMERA_OFFSET_X, CAMERA_OFFSET_Y, CAMERA_OFFSET_Z));

	//Rotate the camera to face the player, and so that player appears to face to the right.
	ThirdPersonCameraComponent->SetRelativeRotation(FRotator(CAMERA_ROTATE_X, CAMERA_ROTATE_Y, CAMERA_ROTATE_Z));

	//Indicator whether a flap has been initiated
	bFlap = false;
	bFlapInitiated = false;

	//Initialize vector speed
	zspeed = 0.0f;

	//Initailize Player State
	state = ST_READY;

	//DEBUG
	FVector pos = GetActorLocation();
	FVector campos = ThirdPersonCameraComponent->GetComponentLocation();
	const auto debug_msg = FString::Printf(TEXT("Eagle X = %f, Y = %f, Z = %f; Camera X = %f, Y = %f, Z = %f"), pos.X, pos.Y, pos.Z, campos.X, campos.Y, campos.Z);
	GEngine->AddOnScreenDebugMessage(-1, 5.0f, FColor::Blue, debug_msg);

	//Detach the camera so it doesn't bounce with the player
	ThirdPersonCameraComponent->DetachFromComponent(FDetachmentTransformRules::KeepWorldTransform);	//Unreal Engine Launch crashes due to this line.
	
}
1 Like