How would I go about referencing different particle effects that were set in the BP editor?
Specifically, I’d like to create a TArray that would describe health level, and a reference pointer to the particle effect to trigger once the actor health fell below the health level:
USTRUCT(BlueprintType)
struct FMyParticleEffect
{
GENERATED_USTRUCT_BODY()
UPROPERTY(EditAnywhere)
float HealthLevel;
UPROPERTY(EditAnywhere)
FName ParticleSystemName;
UPROPERTY()
bool isActivated;
};
The TSubclassOf doesn’t work, and I haven’t tried TAssetPtr types yet, but I thought I would ask if this is possible first.
Basically I want to be able to add several different particle effects to my actor/pawn in the BP editor, then set an initial health, and as the health drops trigger the particle effects at the appropriate time in C++.
My work around was to use the Health Level along with an FName that matched the ParticleSystemComponent name. Then on taking damage I’m searching for a match and activating it:
float AMyPawn::TakeDamage(float DamageAmount, struct FDamageEvent const& DamageEvent, AController* EventInstigator, AActor* DamageCauser)
{
FColor DisplayColor = FColor::Yellow;
const FString DebugMessage(GetName() + " - taking damage");
GEngine->AddOnScreenDebugMessage(-1, 5.0f, DisplayColor, DebugMessage);
CurrentHealth -= FMath::Abs(DamageAmount);
const TArray<UActorComponent*>& theComponents = GetComponents();
int32 componentCount = theComponents.Num();
int32 effectCount = Effects.Num();
for (int32 x = 0; x < effectCount; x++)
{
if (!Effects[x].isActivated && Effects[x].HealthLevel > CurrentHealth)
{
for (int32 y = 0; y < componentCount; y++)
{
UParticleSystemComponent* effect = Cast<UParticleSystemComponent>(theComponents[y]);
if (effect)
{
if (effect->GetFName().Compare(Effects[x].ParticleSystemName) == 0)
{
effect->Activate();
Effects[x].isActivated = true;
break;
}
}
}
}
}
if (CurrentHealth <= 0.0f)
Destroy();
return DamageAmount;
}