Hi,
what you are doing here, is to bind a function to OnComponentBeginOverlap. Something extremely confusing – you are naming that function in the same way a native event is called – that is “OnActorBeginOverlap”. I’d start by creating your own function to bind OnComponentBeginOverlap to. For example, let’s call it simply onOverlap; it has to be a UFUNCTION otherwise you can’t bind it with AddDynamic. That alone makes everything works. I did actually test it and… it works indeed. Code below.
Cheers
f
in zone.h
virtual void PostInitializeComponents() override;
UFUNCTION()
virtual void onOverlap(UPrimitiveComponent* OverlappedComponent, AActor* OtherActor, UPrimitiveComponent* OtherComp, int32 OtherBodyIndex, bool bFromSweep, const FHitResult& SweepResult);
UPROPERTY(EditAnywhere)
UStaticMeshComponent* CollisionMesh;
in Zone.cpp
void AZone::PostInitializeComponents()
{
Super::PostInitializeComponents();
CollisionMesh->OnComponentBeginOverlap.AddDynamic(this, &AZone::onOverlap);
}
void AZone::onOverlap(UPrimitiveComponent* OverlappedComponent, AActor* OtherActor, UPrimitiveComponent* OtherComp, int32 OtherBodyIndex, bool bFromSweep, const FHitResult& SweepResult)
{
GEngine->AddOnScreenDebugMessage(-1, 5.f, FColor::Red, FString::Printf(TEXT("This is the Zone")));
}
in Dangerzone.h
// note there's no need of UFUNCTION as it has that specifier already in its base definition
virtual void onOverlap(UPrimitiveComponent* OverlappedComponent, AActor* OtherActor, UPrimitiveComponent* OtherComp, int32 OtherBodyIndex, bool bFromSweep, const FHitResult& SweepResult) override;
in Dangerzone.cpp
void ADangerZone::onOverlap(UPrimitiveComponent* OverlappedComponent, AActor* OtherActor, UPrimitiveComponent* OtherComp, int32 OtherBodyIndex, bool bFromSweep, const FHitResult& SweepResult)
{
Super::onOverlap(OverlappedComponent, OtherActor, OtherComp, OtherBodyIndex, bFromSweep, SweepResult);
GEngine->AddOnScreenDebugMessage(-1, 5.f, FColor::Red, FString::Printf(TEXT("This is the Danger Zone")));
}