I decided to return to this and was able to come up will a solution.
I am no longer using the module that was generating the BloodPool decals. Now in my BloodDroplet module I use an Export Particle Data to Blueprint. The Condition To Export Data uses the Particles HasCollided Bool Variable. I send the Particles Position as the vector to send and for the struct velocity I use the Particles Collision SafeCombinedCollision Normal. Under export I use a User created variable called User_BloodCallbackHandler (this will be called in the c++ function).
I then created a c++ class BloodDecalSystem.
Here is what the header file looks like:
#pragma once
#include "CoreMinimal.h"
#include "Subsystems/WorldSubsystem.h"
#include "NiagaraDataInterfaceExport.h"
#include "BloodDecalSystem.generated.h"
class UMaterialInterface;
class UDecalComponent;
UCLASS()
class XXXXXX_API UBloodDecalSystem : public UWorldSubsystem, public INiagaraParticleCallbackHandler
{
GENERATED_BODY()
public:
UPROPERTY(Transient)
TObjectPtr<UMaterialInterface> BloodDecalMaterial;
UPROPERTY(Transient)
FVector2D DecalSizeRange = FVector2D(30.0f, 70.0f);
// Maximum persistent decals allowed in the current zone before recycling the oldest
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Blood Decals")
int32 MaxActiveDecals = 250;
// Call this manually to stream/unload a room without reloading the entire World
UFUNCTION(BlueprintCallable, Category = "Blood Decals")
void ClearAllDecals();
virtual void Deinitialize() override;
virtual void ReceiveParticleData_Implementation(
const TArray<FBasicParticleData>& Data,
UNiagaraSystem* NiagaraSystem,
const FVector& SimulationPositionOffset
) override;
private:
// Ring buffer tracking active decals in spawn order
UPROPERTY(Transient)
TArray<TWeakObjectPtr<UDecalComponent>> ActiveDecalPool;
// Cache a Dynamic Material Instance per pool slot so recycling is zero-allocation
UPROPERTY(Transient)
TArray<TObjectPtr<UMaterialInstanceDynamic>> DecalMIDPool;
int32 PoolWriteIndex = 0;
};
and here is what the cpp file looks like:
#include "BloodDecalSystem.h"
#include "Kismet/GameplayStatics.h"
#include "Components/DecalComponent.h"
#include "Materials/MaterialInterface.h"
void UBloodDecalSystem::ReceiveParticleData_Implementation(
const TArray<FBasicParticleData>& Data,
UNiagaraSystem* NiagaraSystem,
const FVector& SimulationPositionOffset)
{
UWorld* World = GetWorld();
if (!World || !BloodDecalMaterial || MaxActiveDecals <= 0) return;
if (ActiveDecalPool.Num() != MaxActiveDecals)
{
ActiveDecalPool.SetNum(MaxActiveDecals);
DecalMIDPool.SetNum(MaxActiveDecals);
PoolWriteIndex = 0;
}
for (const FBasicParticleData& Particle : Data)
{
FVector Start = Particle.Position + FVector(0.0f, 0.0f, 30.0f);
FVector End = Particle.Position - FVector(0.0f, 0.0f, 100.0f);
FHitResult Hit;
FCollisionQueryParams QueryParams;
if (!World->LineTraceSingleByChannel(Hit, Start, End, ECC_GameTraceChannel1, QueryParams))
{
continue;
}
FVector SpawnLocation = Hit.ImpactPoint;
// 1. RANDOM ROTATION AROUND SURFACE NORMAL (Your Z-axis / Roll randomization)
FRotator DecalRotation = (-Hit.ImpactNormal).Rotation();
DecalRotation.Roll = FMath::RandRange(0.0f, 360.0f);
// 2. RANDOM NON-UNIFORM SCALE (Min/Max width & length for organic stretch)
float ScaleY = FMath::RandRange(DecalSizeRange.X, DecalSizeRange.Y);
float ScaleZ = FMath::RandRange(DecalSizeRange.X, DecalSizeRange.Y);
FVector DecalSize(120.0f, ScaleY, ScaleZ); // X = projection depth
// 3. RANDOM 2x2 ATLAS FRAME (0, 1, 2, or 3 -> converted to 0.0, 0.25, 0.5, 0.75)
int32 RandomQuadrant = FMath::RandRange(0, 3);
float FramePhaseValue = static_cast<float>(RandomQuadrant) / 4.0f;
UDecalComponent* Decal = ActiveDecalPool[PoolWriteIndex].Get();
UMaterialInstanceDynamic* MID = DecalMIDPool[PoolWriteIndex];
if (IsValid(Decal))
{
Decal->SetWorldLocationAndRotation(SpawnLocation, DecalRotation);
Decal->DecalSize = DecalSize;
if (!IsValid(MID))
{
MID = UMaterialInstanceDynamic::Create(BloodDecalMaterial, this);
DecalMIDPool[PoolWriteIndex] = MID;
}
if (MID)
{
MID->SetScalarParameterValue(FName("FramePhase"), FramePhaseValue);
Decal->SetDecalMaterial(MID);
}
Decal->MarkRenderStateDirty();
}
else
{
MID = UMaterialInstanceDynamic::Create(BloodDecalMaterial, this);
if (MID)
{
MID->SetScalarParameterValue(FName("FramePhase"), FramePhaseValue);
}
Decal = UGameplayStatics::SpawnDecalAtLocation(
World,
MID ? static_cast<UMaterialInterface*>(MID) : BloodDecalMaterial.Get(),
DecalSize,
SpawnLocation,
DecalRotation,
0.0f
);
if (Decal)
{
Decal->SetFadeScreenSize(0.0005f);
ActiveDecalPool[PoolWriteIndex] = Decal;
DecalMIDPool[PoolWriteIndex] = MID;
}
}
PoolWriteIndex = (PoolWriteIndex + 1) % MaxActiveDecals;
}
}
void UBloodDecalSystem::ClearAllDecals()
{
for (TWeakObjectPtr<UDecalComponent>& DecalPtr : ActiveDecalPool)
{
if (UDecalComponent* Decal = DecalPtr.Get())
{
Decal->DestroyComponent();
}
}
ActiveDecalPool.Empty();
PoolWriteIndex = 0;
}
void UBloodDecalSystem::Deinitialize()
{
ClearAllDecals();
Super::Deinitialize();
}
To generate the Niagara effect I actually use a custom cue class since I am implementing GAS.
This is what I call in my GCN_MeleeHit.h for the blood splatter section:
// 5. BLOOD SPLATTER
UPROPERTY(EditDefaultsOnly, BlueprintReadOnly, Category = "Hit Effects | Visuals")
TObjectPtr<UNiagaraSystem> BloodSplatterFX;
UPROPERTY(EditDefaultsOnly, BlueprintReadOnly, Category = "Hit Effects | Visuals")
TObjectPtr<UMaterialInterface> BloodDecalMaterial;
UPROPERTY(EditDefaultsOnly, BlueprintReadOnly, Category = "Hit Effects | Visuals")
FVector2D BloodDecalSizeRange = FVector2D(30.0f, 70.0f);
Then this is the function that executes the blood splatter:
void UGCN_MeleeHit::SpawnBloodSplatter(UWorld* World, AActor* MyTarget, const FGameplayCueParameters& Parameters) const
{
AActor* Attacker = Parameters.Instigator.Get();
if (!Attacker || !MyTarget || !BloodSplatterFX) return;
// 1. Start with the actual hit location (comes from weapon's trace / overlap)
FVector HitPoint = Parameters.Location;
// Fallback if Parameters.Location wasn't populated by the ability
if (HitPoint.IsNearlyZero())
{
HitPoint = MyTarget->GetActorLocation();
}
// 2. SNAP TO VISUAL MESH (Handles floating enemies where mesh is offset above capsule)
USkeletalMeshComponent* SkelMesh = MyTarget->FindComponentByClass<USkeletalMeshComponent>();
if (SkelMesh)
{
FVector PointOnMesh = FVector::ZeroVector;
if (SkelMesh->GetClosestPointOnCollision(HitPoint, PointOnMesh) > 0.0f)
{
HitPoint = PointOnMesh;
}
else
{
// If the mesh has no physics asset collision, use the mesh's bounds center at the hit's Z height
FVector MeshOrigin = SkelMesh->Bounds.Origin;
HitPoint = FVector(MeshOrigin.X, MeshOrigin.Y, HitPoint.Z);
}
}
// 3. Calculate horizontal attack direction (Attacker -> Mesh Center, ignoring vertical height difference)
FVector MeshCenter = SkelMesh ? SkelMesh->Bounds.Origin : MyTarget->GetActorLocation();
FVector AttackDirection = (MeshCenter - Attacker->GetActorLocation());
AttackDirection.Z = 0.0f; // Keep horizontal so hitting a high floating enemy doesn't aim the spray into the ceiling
if (!AttackDirection.Normalize())
{
AttackDirection = MyTarget->GetActorForwardVector();
}
// 4. Push spawn point through the mesh to the backside exit wound
float ExitOffset = 35.0f;
if (SkelMesh)
{
// Use the horizontal bounds radius of the floating mesh rather than the ground capsule
ExitOffset = FMath::Max(SkelMesh->Bounds.BoxExtent.X, SkelMesh->Bounds.BoxExtent.Y) * 0.85f;
}
else if (const ACharacter* TargetChar = Cast<ACharacter>(MyTarget))
{
if (const UCapsuleComponent* Capsule = TargetChar->GetCapsuleComponent())
{
ExitOffset = Capsule->GetUnscaledCapsuleRadius();
}
}
// Start from the snapped hit height, centered horizontally on the mesh, and push out the back
FVector ExitLocation = FVector(MeshCenter.X, MeshCenter.Y, HitPoint.Z) + (AttackDirection * ExitOffset);
// 5. Add slight upward isometric arc after calculating the exit point
FVector SprayDirection = AttackDirection;
SprayDirection.Z += 0.2f;
SprayDirection.Normalize();
// 6. Spawn the exit wound particle system at the floating mesh's backside
UNiagaraComponent* BloodComp = UNiagaraFunctionLibrary::SpawnSystemAtLocation(
World,
BloodSplatterFX,
ExitLocation,
SprayDirection.Rotation()
);
if (BloodComp)
{
if (UBloodDecalSystem* DecalSubsystem = World->GetSubsystem<UBloodDecalSystem>())
{
DecalSubsystem->BloodDecalMaterial = BloodDecalMaterial;
DecalSubsystem->DecalSizeRange = BloodDecalSizeRange;
BloodComp->SetVariableObject(TEXT("User.User_BloodCallbackHandler"), DecalSubsystem);
}
}
}
Then for my custom cue class I just input the decal material and set the range size from my GCN_Hit class. This has resulted in every collision spawning a decal.
Removed the blood pool decal spawn emitter:
The decal will no longer be getting spawned through Niagara’s Emitters
Added an Export Particle to Blueprint module:
We will use the exported data to spawn the decals through a custom C++ class.
Set the variables for the Export module:
Set the blood decal material and settings in my custom GameplayCueNotify Static class: