I currently have this setup (.cpp):
AFire::AFire(const class FObjectInitializer& ObjectInitializer)
{
ProxSphere = ObjectInitializer.CreateDefaultSubobject<USphereComponent>(this, TEXT("Sphere Component"));
ProxSphere->AttachToComponent(RootComponent, FAttachmentTransformRules::KeepWorldTransform);
ProxSphere->SetSphereRadius(32.f);
ProxSphere->OnComponentBeginOverlap.AddDynamic(this, &AFire::Prox);
// 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;
PrimaryActorTick.bStartWithTickEnabled = true;
}
void AFire::Prox_Implementation(UPrimitiveComponent* HitComp, AActor* OtherActor, UPrimitiveComponent* OtherComp, int32 OtherBodyIndex, bool bFromSweep, const FHitResult &SweepResult)
{
if (Cast<AMyCharacter>(OtherActor) == nullptr)
{
return;
}
if (Cast<AMyCharacter>(OtherActor))
{
AMyCharacter* Character = Cast<AMyCharacter>(OtherActor);
Character->Damage(Character->GetHp(), 6.f);
}
}
.h:
UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = "Collision")
USphereComponent* ProxSphere;
UFUNCTION(BlueprintNativeEvent, Category = "Collision")
void Prox(UPrimitiveComponent* HitComp, AActor* OtherActor, UPrimitiveComponent* OtherComp, int32 OtherBodyIndex, bool bFromSweep, const FHitResult &SweepResult);
This is successful in damaging my character every time I walk onto it, but it doesn’t loop so if I stand on top of it I don’t continue to take damage. I can’t move this to the Tick class.
I tried adding a while loop, but it made my program crash:
void AFire::Prox_Implementation(UPrimitiveComponent* HitComp, AActor* OtherActor, UPrimitiveComponent* OtherComp, int32 OtherBodyIndex, bool bFromSweep, const FHitResult &SweepResult)
{
if (Cast<AMyCharacter>(OtherActor) == nullptr)
{
return;
}
if (Cast<AMyCharacter>(OtherActor))
{
while (Cast <AMyCharacter>(OtherActor))
{
AMyCharacter* Character = Cast<AMyCharacter>(OtherActor);
Character->Damage(Character->GetHp(), 6.f);
}
}
}
Is there any way to make my collision tick so it can check every second if my character is colliding with it?