Hi, I am making a function that fires when the character overlaps, but it doesn’t work (at least it doesn’t output “OPA”)
The compiler does not print errors
Header File
#pragma once
#include "CoreMinimal.h"
#include "GameFramework/Actor.h"
#include "Engine.h"
#include "ACollectible.generated.h"
UCLASS()
class TESTPROJECT_API AACollectible : public AActor
{
GENERATED_BODY()
public:
// Sets default values for this actor's properties
AACollectible();
UPROPERTY(VIsibleAnywhere)
UStaticMeshComponent* SM;
UPROPERTY(VIsibleAnywhere)
URotatingMovementComponent* RotatingComp;
UFUNCTION()
void OnOverlap(AActor* MyOverlappedActor, AActor* OtherActor);
protected:
// Called when the game starts or when spawned
virtual void BeginPlay() override;
public:
// Called every frame
virtual void Tick(float DeltaTime) override;
};
Source File
#include "ACollectible.h"
#include "TestProjectCharacter.h"
// Sets default values
AACollectible::AACollectible()
{
// 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;
SM = CreateDefaultSubobject<UStaticMeshComponent>(TEXT("StaticMesh"));
RotatingComp = CreateDefaultSubobject<URotatingMovementComponent>(TEXT("RotatingMovementComponent"));
OnActorBeginOverlap.AddDynamic(this, &AACollectible::OnOverlap);
}
// Called when the game starts or when spawned
void AACollectible::BeginPlay()
{
Super::BeginPlay();
}
// Called every frame
void AACollectible::Tick(float DeltaTime)
{
Super::Tick(DeltaTime);
}
void AACollectible::OnOverlap(AActor* MyOverlappedActor, AActor* OtherActor)
{
GLog->Log(TEXT("OPAOPAOPAOPA"));
ATestProjectCharacter* Char = Cast<ATestProjectCharacter>(OtherActor);
if (Char)
{
FText Text = FText::FromString(GetName());
GLog->Log(TEXT("ItemAdded"));
Char->AddItemToUI(Text);
Destroy();
}
}