Hi
I’m currently trying to spawn blood decals when blood particles hit the floor.
To achieve this I added an event generator of type collision on the particle system and I tried to bind the event to a function. However the bound function OnBloodParticleCollide is getting triggered. I can’t seem to find what I’m doing wrong, also my code seems to be styled in a weird manner in this post. I’ve seen other posts that had a way better representation of the code. Is there a better way to style it?
GEngine->AddOnScreenDebugMessage(-1, 20.0f, FColor::Cyan, TEXT("Bind on particle collide"));
TScriptDelegate<FWeakObjectPtr> particleCollide;
particleCollide.BindUFunction(this, "OnBloodParticleCollide");
particleSystemComponent->OnParticleCollide.AddUnique(particleCollide);
.h
UFUNCTION()
void OnBloodParticleCollide(FName EventName, float EmitterTime, int32 ParticleTime, FVector Location, FVector Velocity, FVector Direction, FVector Normal, FName BoneName, UPhysicalMaterial* PhysMat);
.cpp
void AProjectile::OnBloodParticleCollide(FName EventName, float EmitterTime, int32 ParticleTime, FVector Location, FVector Velocity, FVector Direction, FVector Normal, FName BoneName, UPhysicalMaterial* PhysMat)
{
GEngine->AddOnScreenDebugMessage(-1, 20.0f, FColor::Cyan, TEXT("Blood colliding"));
if (BloodDecalMaterial)
{
float randWidth = FMath::RandRange(20.0f, 20.0f);
UGameplayStatics::SpawnDecalAtLocation(this, BloodDecalMaterial, FVector(20.0f, randWidth, randWidth), Location, Normal.Rotation());
}
}