I’m running through the C++ First person shooter tutorial (4.15) and I’m running into an error I don’t understand. It claims that the USkeletalMeshComponent class does not have a SetupAttachement member function, but I can clearly see that USkeletalMeshComponent derives from USceneComponent. It gives the same error even if I cast my USkeletalMeshComponent as a USceneComponent. Any idea why?
Here’s my header:
// Fill out your copyright notice in the Description page of Project Settings.
#pragma once
#include "CoreMinimal.h"
#include "GameFramework/Character.h"
#include "FPSCharacter.generated.h"
class UCameraComponent;
class USkeletalMeshComponent;
UCLASS()
class FPSPROJECT_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 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);
//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;
//First-person mesh (arms), visible only to the owning player
UPROPERTY(VisibleDefaultsOnly, Category = Mesh) USkeletalMeshComponent* FPSMesh;
};
And my implementation:
// Fill out your copyright notice in the Description page of Project Settings.
#include "FPSCharacter.h"
#include "Camera/CameraComponent.h"
#include "Components/SkeletalMeshComponent.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((USceneComponent*) GetCapsuleComponent());
//Position the camera slightly above the eyes
FPSCameraComponent->SetRelativeLocation(FVector(0, 0, 50.0f + BaseEyeHeight));
//allow the pawn to control camera rotation
FPSCameraComponent->bUsePawnControlRotation = true;
//Createa a first person mesh component for the owning player
FPSMesh = CreateDefaultSubobject<USkeletalMeshComponent>(TEXT("FirstPersonMesh"));
//Only the owning player sees this mesh
FPSMesh->SetOnlyOwnerSee(true);
//Attach the FPS mesh to the FPS camera
FPSMesh->SetupAttachement(FPSCameraComponent);
//Disable some environmental shadowing to preserve the illusion of having a single mesh
FPSMesh->bCastDynamicShadow = false;
FPSMesh->CastShadow = false;
//the owning player doesn't see the regular (third-person) body mesh
GetMesh()->SetOwnerNoSee(true);
}
// Called when the game starts or when spawned
void AFPSCharacter::BeginPlay()
{
Super::BeginPlay();
//depracated
/*
if (GEngine) {
// Put up a debug message for five seconds. The -1 "Key" value (first argument) indicates that we will never
// need to update or refresh this message.
GEngine->AddOnScreenDebugMessage(-1, 5.0f, FColor::Red, 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);
//Set up "movement" bindings
PlayerInputComponent->BindAxis("MoveForward", this, &AFPSCharacter::MoveForward);
PlayerInputComponent->BindAxis("MoveRight", this, &AFPSCharacter::MoveRight);
//Set player "look" bindings.
PlayerInputComponent->BindAxis("Turn", this, &AFPSCharacter::AddControllerYawInput);
PlayerInputComponent->BindAxis("LookUp", this, &AFPSCharacter::AddControllerPitchInput);
//Set Player action bindings
PlayerInputComponent->BindAction("Jump", IE_Pressed, this, &AFPSCharacter::StartJump);
PlayerInputComponent->BindAction("Jump", IE_Released, this, &AFPSCharacter::StopJump);
}
void AFPSCharacter::MoveForward(float Value) {
//Find out which was 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 was 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;
}
All I have to do to get it to compile is comment out the FPSMesh->SetupAttachement(FPSCameraComponent); line.
Edit: Oops, posted the wrong line down here.
Thanks for your help!