Here is my code (i even almost copied it from documentation)
Here is my code…
BattleZone.h
#pragma once
#include "GameFramework/Actor.h"
#include "BattleZone.generated.h"
UCLASS()
class NOCOUNTRYFORTHEM_API ABattleZone : public AActor
{
GENERATED_BODY()
public:
// Sets default values for this actor's properties
ABattleZone(const FObjectInitializer& ObjectInitializer);
// Called when the game starts or when spawned
virtual void BeginPlay() override;
// Called every frame
virtual void Tick( float DeltaSeconds ) override;
UPROPERTY(VisibleAnywhere, Category = "Box")
class UBoxComponent* CollisionBox;
//void OnBeginTriggerOverlap(class UPrimitiveComponent* HitComp, class AActor* OtherActor, class UPrimitiveComponent* OtherComp, int32 OtherBodyIndex, bool bFromSweep, const FHitResult& SweepResult);
UFUNCTION()
void OnOverlapBegin(UPrimitiveComponent* OverlappedComp, AActor* OtherActor, UPrimitiveComponent* OtherComp, int32 OtherBodyIndex, bool bFromSweep, const FHitResult& SweepResult);
UFUNCTION()
void OnOverlapEnd(UPrimitiveComponent* OverlappedComp, AActor* OtherActor, UPrimitiveComponent* OtherComp, int32 OtherBodyIndex);
};
BattleZone.cpp
ABattleZone::ABattleZone(const FObjectInitializer& ObjectInitializer)
:Super(ObjectInitializer)
{
CollisionBox = CreateDefaultSubobject<UBoxComponent>(TEXT("CollisionBox"));
RootComponent = CollisionBox;
CollisionBox->bGenerateOverlapEvents = true;
CollisionBox->OnComponentBeginOverlap.AddDynamic(this, &ABattleZone::OnOverlapBegin);
CollisionBox->OnComponentEndOverlap.AddDynamic(this, &ABattleZone::OnOverlapEnd);;
//Set this actor to call Tick() Everyframe. YOu can turn this off to improve performance if you don't need it.
PrimaryActorTick.bCanEverTick = false;
}
void ABattleZone::OnOverlapBegin(UPrimitiveComponent* OverlappedComp, AActor* OtherActor, UPrimitiveComponent* OtherComp, int32 OtherBodyIndex, bool bFromSweep, const FHitResult& SweepResult)
{
if ((OtherActor != nullptr) && (OtherActor != this) && (OtherComp != nullptr))
{
GEngine->AddOnScreenDebugMessage(-1, 15.0f, FColor::Red, "Battle starts");
}
}
void ABattleZone::OnOverlapEnd(UPrimitiveComponent* OverlappedComp, AActor* OtherActor, UPrimitiveComponent* OtherComp, int32 OtherBodyIndex)
{
if ((OtherActor != nullptr) && (OtherActor != this) && (OtherComp != nullptr))
{
GEngine->AddOnScreenDebugMessage(-1, 15.0f, FColor::Red, "Battle End");
}
}
Base_Character.h
class NOCOUNTRYFORTHEM_API ABase_Character : public APawn
{
// Sets default values for this pawn's properties
ABase_Character(const FObjectInitializer& ObjectInitializer);
}
Base_Character.cpp
ABase_Character::ABase_Character(const FObjectInitializer& ObjectInitializer)
:Super(ObjectInitializer)
{
// Set this pawn to call Tick() every frame. You can turn this off to improve performance if you don't need it.
PrimaryActorTick.bCanEverTick = true;
CollisionBox = CreateDefaultSubobject<UBoxComponent>(TEXT("CollisionBox"));
//RootComponent = CollisionBox;
CollisionBox->AttachToComponent(RootComponent, FAttachmentTransformRules::KeepRelativeTransform);
CollisionBox->bGenerateOverlapEvents = true;
}
As you can see… BattleZone is an Actor with collision box and Base_Character is a Pawn with Paper2D Sprite with few statistic. they both suppose to overlap at beginning with message… but only messages pops out when they departs each other.
I am hopeless… if this is solved asap, I may reach my own deadline…