hey , trying to follow a tutorial about picking up an actor , the code compiled successfully but when i play the actor can’t be picked up , here’s the code :
HEADER :
// Fill out your copyright notice in the Description page of Project Settings.
#pragma once
#include “Classes/Components/BoxComponent.h”
#include “CoreMinimal.h”
#include “GameFramework/Actor.h”
#include “Pickup.generated.h”
UCLASS()
class CIIKBOOK_API APickup : public AActor
{
GENERATED_BODY()
public:
// Sets default values for this actor’s properties
APickup();
UPROPERTY(EditAnywhere)
UBoxComponent* PickupBox;
UPROPERTY(EditAnywhere)
UStaticMeshComponent* PickupMesh;
UFUNCTION()
void OnPickedup(UPrimitiveComponent* OverlappedComponent, AActor* OtherActor, UPrimitiveComponent* OtherComp, int32 OtherBodyIndex, bool bFromSweep, const FHitResult& SweepResult);
protected:
// Called when the game starts or when spawned
virtual void BeginPlay() override;
public:
// Called every frame
virtual void Tick(float DeltaTime) override;
};
.CPP :
// Fill out your copyright notice in the Description page of Project Settings.
#include “Pickup.h”
#include “CiikBook.h”
// Sets default values
APickup::APickup()
{
// 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;
PickupBox = CreateDefaultSubobject<UBoxComponent>("PickupBox");
PickupBox -> OnComponentBeginOverlap.AddDynamic(this, &APickup::OnPickedup);
PickupMesh = CreateDefaultSubobject<UStaticMeshComponent>("PickupMesh");
}
void APickup::OnPickedup(UPrimitiveComponent* OverlappedComponent, AActor* OtherActor, UPrimitiveComponent* OtherComp, int32 OtherBodyIndex, bool bFromSweep, const FHitResult& SweepResult)
{
Destroy();
}
// Called when the game starts or when spawned
void APickup::BeginPlay()
{
Super::BeginPlay();
}
// Called every frame
void APickup::Tick(float DeltaTime)
{
Super::Tick(DeltaTime);
}