So I’m only on the 4th C++ tutorial video and I’m already stuck.
I’m trying to extend the batteryPickup class from the Pickup class and the error I get is this:
1>BatteryPickup.cpp.obj : error LNK2019: unresolved external symbol "public: __cdecl APickUp::APickUp(void)" (??0APickUp@@QEAA@XZ) referenced in function "public: __cdecl ABatteryPickup::ABatteryPickup(void)" (??0ABatteryPickup@@QEAA@XZ)
I read that
APickup::APickup(const class FPostConstructInitializeProperties& PCIP): Super(PCIP)
should be replaced with:
APickUp::APickUp(const class FObjectInitializer& ObjectInitializer) : Super(ObjectInitializer)
which is what I’ve done. Any how, if someone could tell me what I’m doing wrong, that would be great.
The Pickup.h class:
#pragma once
#include "GameFramework/Actor.h"
#include "PickUp.generated.h"
UCLASS()
class TUTORIALCODE_API APickUp : public AActor
{
GENERATED_UCLASS_BODY()
public:
APickUp();
// Called when the game starts or when spawned
virtual void BeginPlay() override;
// Called every frame
virtual void Tick( float DeltaSeconds ) override;
/** True when the pickup is able to be picked up, false if something deactivates the pickup. */
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = Pickup)
bool bIsActive;
/** Simple collision primitive to use as the root component. */
UPROPERTY(VisibleDefaultsOnly, BlueprintReadOnly, Category = Pickup)
class USphereComponent* BaseCollisionComponent;
/** StaticMeshComponent to represent the pickup in the level. */
UPROPERTY(VisibleDefaultsOnly, BlueprintReadOnly, Category = Pickup)
class UStaticMeshComponent* PickupMesh;
/** Function to call when the Pickup is collected. */
UFUNCTION(BlueprintNativeEvent)
void OnPickedUp();
};
the PickUp.cpp file:
#include "TutorialCode.h"
#include "PickUp.h"
APickUp::APickUp(const class FObjectInitializer& ObjectInitializer) : Super(ObjectInitializer)
{
// Set this actor to call Tick() every frame. You can turn this off to improve performance if you don't need it.
PrimaryActorTick.bCanEverTick = true;
// The pickup is valid when it is created.
bIsActive = true;
// Create the root SphereComponent to handle the pickup's collision
BaseCollisionComponent = ObjectInitializer.CreateDefaultSubobject<USphereComponent>(this, TEXT("BaseSphereComponent"));
// Set the SphereComponent as the root component.
RootComponent = BaseCollisionComponent;
// Create the StaticMeshComponent.
PickupMesh = ObjectInitializer.CreateDefaultSubobject<UStaticMeshComponent>(this, TEXT("PickupMesh"));
// Turn physics on for the static mesh.
PickupMesh->SetSimulatePhysics(true);
// Attach the StaticMeshComponent to the RootComponent.
PickupMesh->AttachTo(RootComponent);
}
void APickUp::OnPickedUp_Implementation()
{
// There is no default behavior for a Pickup when it is picked up.
}
// Called when the game starts or when spawned
void APickUp::BeginPlay()
{
Super::BeginPlay();
}
// Called every frame
void APickUp::Tick( float DeltaTime )
{
Super::Tick( DeltaTime );
}
The BatteryPickup.h file:
#pragma once
#include "PickUp.h"
#include "BatteryPickup.generated.h"
/**
*
*/
UCLASS()
class ABatteryPickup : public APickUp
{
//defaults to private
GENERATED_BODY()
public:
ABatteryPickup();
//Amount of power to give to the player
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = Power)
float PowerLevel;
//Overide the OnPickedUp function implementation
void OnPickedUp_Implementation() override;
};
the BatteryPickup.CPP file:
#include "TutorialCode.h"
#include "BatteryPickup.h"
ABatteryPickup::ABatteryPickup()
{
//The base power level of the battery
PowerLevel = 150.f;
}
void ABatteryPickup::OnPickedUp_Implementation()
{
Super::OnPickedUp_Implementation();
//Destroy the battery
Destroy();
}
Thanks