If I use:
AFire::AFire(const class FObjectInitializer& ObjectInitializer)
{
ProxSphere = ObjectInitializer.CreateDefaultSubobject<USphereComponent>(this, TEXT("Sphere Component"));
ProxSphere->AttachToComponent(RootComponent, FAttachmentTransformRules::KeepWorldTransform);
ProxSphere->SetSphereRadius(32.f);
Character = nullptr;
bDamage = false;
ProxSphere->OnComponentBeginOverlap.AddDynamic(this, &AFire::OnActorBeginOverlap);
ProxSphere->OnComponentEndOverlap.AddDynamic(this, &AFire::OnActorEndOverlap);
PrimaryActorTick.bCanEverTick = true;
}
The functions don’t work, but if I place them in BeginPlay they work as expected. Anyone know why? I don’t think it’s ideal for me to put these in my BeginPlay function.
Working code:
// Sets default values
AFire::AFire(const class FObjectInitializer& ObjectInitializer)
{
ProxSphere = ObjectInitializer.CreateDefaultSubobject<USphereComponent>(this, TEXT("Sphere Component"));
ProxSphere->AttachToComponent(RootComponent, FAttachmentTransformRules::KeepWorldTransform);
ProxSphere->SetSphereRadius(32.f);
Character = nullptr;
bDamage = false;
// 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;
}
// Called when the game starts or when spawned
void AFire::BeginPlay()
{
Super::BeginPlay();
ProxSphere->OnComponentBeginOverlap.AddDynamic(this, &AFire::OnActorBeginOverlap);
ProxSphere->OnComponentEndOverlap.AddDynamic(this, &AFire::OnActorEndOverlap);
}