I’m working through this area of the tutorial:
https://docs.unrealengine.com/latest/INT/Programming/Tutorials/FirstPersonShooter/2/7/index.html
If I comment out this line:
FPSCameraComponent->SetupAttachment(GetCapsuleComponent());
It compiles and works fine.
However, if I don’t it throws the error below, which confuses me greatly since UCapsuleComponent obviously inherits USceneComponent.
Severity Code Description Project File Line Suppression State
Error C2664 'void USceneComponent::SetupAttachment(USceneComponent *,FName)': cannot convert argument 1 from 'UCapsuleComponent *' to 'USceneComponent *' Raid C:\Software\Raid\Source\Raid\Private\Characters\FPSCharacter.cpp 16
Please Help. I have no clue what I’m doing wrong here.
Full CPP, Headers, and Log. Thank you for your help.
FPSCharacter.h
// Fill out your copyright notice in the Description page of Project Settings.
#pragma once
#include "CoreMinimal.h"
#include "GameFramework/Character.h"
#include "Camera/CameraComponent.h"
#include "FPSCharacter.generated.h"
UCLASS()
class RAID_API AFPSCharacter : public ACharacter
{
GENERATED_BODY()
public:
// Sets default values for this character's properties
AFPSCharacter();
protected:
// Called when the game starts or when spawned
virtual void BeginPlay() override;
public:
// Called every frame
virtual void Tick(float DeltaSeconds) 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);
// Sets jump flag when key is pressed.
UFUNCTION()
void StartJump();
// Clears jump flag when key is released.
UFUNCTION()
void StopJump();
// FPS camera.
UPROPERTY(VisibleAnywhere)
UCameraComponent* FPSCameraComponent;
};
FPSCharacter.cpp
// Fill out your copyright notice in the Description page of Project Settings.
#include "FPSCharacter.h"
// Sets default values
AFPSCharacter::AFPSCharacter()
{
// 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 a first person camera component.
FPSCameraComponent = CreateDefaultSubobject<UCameraComponent>(TEXT("FirstPersonCamera"));
// Attach the camera component to our capsule component.
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;*/
}
// Called when the game starts or when spawned
void AFPSCharacter::BeginPlay()
{
Super::BeginPlay();
if (GEngine)
{
GEngine->AddOnScreenDebugMessage(-1, 5.f, FColor::Blue, TEXT("We are using FPSCharacter!"));
}
}
// Called every frame
void AFPSCharacter::Tick(float DeltaTime)
{
Super::Tick(DeltaTime);
}
// Called to bind functionality to input
void AFPSCharacter::SetupPlayerInputComponent(UInputComponent* PlayerInputComponent)
{
Super::SetupPlayerInputComponent(PlayerInputComponent);
PlayerInputComponent->BindAxis("MoveForward", this, &AFPSCharacter::MoveForward);
PlayerInputComponent->BindAxis("MoveRight", this, &AFPSCharacter::MoveRight);
PlayerInputComponent->BindAxis("Turn", this, &AFPSCharacter::AddControllerYawInput);
PlayerInputComponent->BindAxis("LookUp", this, &AFPSCharacter::AddControllerPitchInput);
PlayerInputComponent->BindAction("Jump", IE_Pressed, this, &AFPSCharacter::StartJump);
PlayerInputComponent->BindAction("Jump", IE_Released, this, &AFPSCharacter::StopJump);
}
void AFPSCharacter::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 AFPSCharacter::MoveRight(float Value)
{
// Find out which way is "right" and record that the player wants to move that way.
FVector Direction = FRotationMatrix(Controller->GetControlRotation()).GetScaledAxis(EAxis::Y);
AddMovementInput(Direction, Value);
}
void AFPSCharacter::StartJump()
{
bPressedJump = true;
}
void AFPSCharacter::StopJump()
{
bPressedJump = false;
}
Error Log
Severity Code Description Project File Line Suppression State
Error Failed to produce item: C:\Software\Raid\Binaries\Win64\UE4Editor-Raid-6566.dll Raid C:\Software\Raid\Intermediate\ProjectFiles\ERROR 1
Error (active) cannot open source file "FPSCharacter.h" Raid c:\Software\Raid\Source\Raid\Private\Characters\FPSCharacter.cpp 3
Error (active) name followed by '::' must be a class or namespace name Raid c:\Software\Raid\Source\Raid\Private\Characters\FPSCharacter.cpp 7
Error (active) identifier "PrimaryActorTick" is undefined Raid c:\Software\Raid\Source\Raid\Private\Characters\FPSCharacter.cpp 10
Error (active) identifier "FPSCameraComponent" is undefined Raid c:\Software\Raid\Source\Raid\Private\Characters\FPSCharacter.cpp 13
Error (active) identifier "CreateDefaultSubobject" is undefined Raid c:\Software\Raid\Source\Raid\Private\Characters\FPSCharacter.cpp 13
Error (active) identifier "UCameraComponent" is undefined Raid c:\Software\Raid\Source\Raid\Private\Characters\FPSCharacter.cpp 13
Error (active) identifier "TEXT" is undefined Raid c:\Software\Raid\Source\Raid\Private\Characters\FPSCharacter.cpp 13
Error (active) identifier "GetCapsuleComponent" is undefined Raid c:\Software\Raid\Source\Raid\Private\Characters\FPSCharacter.cpp 16
Error (active) name followed by '::' must be a class or namespace name Raid c:\Software\Raid\Source\Raid\Private\Characters\FPSCharacter.cpp 26
Error (active) name followed by '::' must be a class or namespace name Raid c:\Software\Raid\Source\Raid\Private\Characters\FPSCharacter.cpp 28
Error (active) identifier "GEngine" is undefined Raid c:\Software\Raid\Source\Raid\Private\Characters\FPSCharacter.cpp 31
Error (active) name followed by '::' must be a class or namespace name Raid c:\Software\Raid\Source\Raid\Private\Characters\FPSCharacter.cpp 33
Error (active) identifier "TEXT" is undefined Raid c:\Software\Raid\Source\Raid\Private\Characters\FPSCharacter.cpp 33
Error (active) name followed by '::' must be a class or namespace name Raid c:\Software\Raid\Source\Raid\Private\Characters\FPSCharacter.cpp 39
Error (active) name followed by '::' must be a class or namespace name Raid c:\Software\Raid\Source\Raid\Private\Characters\FPSCharacter.cpp 41
Error (active) name followed by '::' must be a class or namespace name Raid c:\Software\Raid\Source\Raid\Private\Characters\FPSCharacter.cpp 46
Error (active) identifier "UInputComponent" is undefined Raid c:\Software\Raid\Source\Raid\Private\Characters\FPSCharacter.cpp 46
Error (active) identifier "PlayerInputComponent" is undefined Raid c:\Software\Raid\Source\Raid\Private\Characters\FPSCharacter.cpp 46
Error (active) expected a ';' Raid c:\Software\Raid\Source\Raid\Private\Characters\FPSCharacter.cpp 47
Error C2664 'void USceneComponent::SetupAttachment(USceneComponent *,FName)': cannot convert argument 1 from 'UCapsuleComponent *' to 'USceneComponent *' Raid C:\Software\Raid\Source\Raid\Private\Characters\FPSCharacter.cpp 16
Error MSB3073 The command ""C:\Program Files\Epic Games\UE_4.16\Engine\Build\BatchFiles\Rebuild.bat" RaidEditor Win64 Development "C:\Software\Raid\Raid.uproject" -waitmutex" exited with code -1. Raid C:\Program Files (x86)\MSBuild\Microsoft.Cpp\v4.0\V140\Microsoft.MakeFile.Targets 42