I created a new third person cpp project using Unreal 5.0.3 and created a new class, derived from AActor called MyActor. Here is the cpp/h for this class:
// Fill out your copyright notice in the Description page of Project Settings.
#include "MyActor.h"
#include "Components/BoxComponent.h"
// Sets default values
AMyActor::AMyActor()
{
// 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;
DefaultSceneComponent = CreateDefaultSubobject<USceneComponent>(TEXT("DefaultSceneComponent"));
SetRootComponent(DefaultSceneComponent);
AIGoalCollider = CreateDefaultSubobject<UBoxComponent>(TEXT("AIGoalCollider"));
AIGoalCollider->SetupAttachment(RootComponent);
TopCollider = CreateDefaultSubobject<UBoxComponent>(TEXT("TopCollider"));
TopCollider->SetupAttachment(RootComponent);
BottomCollider = CreateDefaultSubobject<UBoxComponent>(TEXT("BottomCollider"));
BottomCollider->SetupAttachment(RootComponent);
PlayerGoalCollider = CreateDefaultSubobject<UBoxComponent>(TEXT("PlayerGoalCollider"));
PlayerGoalCollider->SetupAttachment(RootComponent);
}
// Called when the game starts or when spawned
void AMyActor::BeginPlay()
{
Super::BeginPlay();
}
void AMyActor::PostInitializeComponents()
{
Super::PostInitializeComponents();
AIGoalCollider->OnComponentBeginOverlap.AddDynamic(this, &AMyActor::OnOverlapBegin);
TopCollider->OnComponentBeginOverlap.AddDynamic(this, &AMyActor::OnOverlapBegin);
BottomCollider->OnComponentBeginOverlap.AddDynamic(this, &AMyActor::OnOverlapBegin);
PlayerGoalCollider->OnComponentBeginOverlap.AddDynamic(this, &AMyActor::OnOverlapBegin);
}
// Called every frame
void AMyActor::Tick(float DeltaTime)
{
Super::Tick(DeltaTime);
}
void AMyActor::OnOverlapBegin(UPrimitiveComponent* HitComp, AActor* OtherActor, UPrimitiveComponent* OtherComp,
int32 OtherBodyIndex, bool bFromSweep, const FHitResult& SweepResult)
{
UE_LOG(LogTemp, Warning, TEXT("OVERLAP: %s"), *HitComp->GetName());
}
// Fill out your copyright notice in the Description page of Project Settings.
#pragma once
#include "CoreMinimal.h"
#include "GameFramework/Actor.h"
#include "MyActor.generated.h"
DECLARE_DYNAMIC_MULTICAST_DELEGATE(FOnWallCollisionSignature);
DECLARE_DYNAMIC_MULTICAST_DELEGATE(FOnAIGoalCollisionSignature);
DECLARE_DYNAMIC_MULTICAST_DELEGATE(FOnPlayerGoalCollisionSignature);
UCLASS()
class DELEGATES_API AMyActor : public AActor
{
GENERATED_BODY()
public:
// Sets default values for this actor's properties
AMyActor();
protected:
// Called when the game starts or when spawned
virtual void BeginPlay() override;
virtual void PostInitializeComponents() override;
public:
// Called every frame
virtual void Tick(float DeltaTime) override;
UFUNCTION()
void OnOverlapBegin(class UPrimitiveComponent* HitComp, class AActor* OtherActor, class UPrimitiveComponent* OtherComp,
int32 OtherBodyIndex, bool bFromSweep, const FHitResult& SweepResult);
public:
UPROPERTY(EditAnywhere, Category = "Component")
class USceneComponent* DefaultSceneComponent;
UPROPERTY(EditAnywhere, Category = "Component")
class UBoxComponent* AIGoalCollider;
UPROPERTY(EditAnywhere, Category = "Component")
class UBoxComponent* TopCollider;
UPROPERTY(EditAnywhere, Category = "Component")
class UBoxComponent* BottomCollider;
UPROPERTY(EditAnywhere, Category = "Component")
class UBoxComponent* PlayerGoalCollider;
UPROPERTY(BlueprintAssignable)
FOnWallCollisionSignature OnWallCollision;
UPROPERTY(BlueprintAssignable)
FOnAIGoalCollisionSignature OnAIGoalCollision;
UPROPERTY(BlueprintAssignable)
FOnPlayerGoalCollisionSignature OnPlayerGoalCollision;
};
To differentiate these box components, I gave them slight offsets in the derived blueprint as shown below:
With this code, and when using PIE, I get the result shown in the attached video:
A potential guess as to why my example works and yours does not is where you are binding the delegates. From my experience, these component delegate bindings are best done in the function PostInitializeComponents(), which is found in the AActor class that you can then override in your class. Binding these delegates in the constructor can cause issues or even compile errors.
I hope this information helps, and if there are still issues, please let me know Good luck!