Hi,
As a self-imposed Mini chalenge, I wanted to protect my MuzzleFlash pointer in case I forgot to set it in blueprint. So I did the following code, but when I tried to play the game, it would crash straight away, instead of just quitting the code before the pointer is used, and giving a more meaningful error message.
Can anyone see or know why my protection to stop it crashing if I don’t set the particle effect in Blueprint isn’t working?
Here is my cpp code
// Called when the game starts or when spawned
void AGun::BeginPlay()
{
Super::BeginPlay();CheckForMuzzleFlash();
}void AGun::CheckForMuzzleFlash() const
{
if (!MuzzleFlash)
{
UE_LOG(LogTemp, Error, TEXT(“No MuzzleFlash particle effect has been attached to the %s.”), *GetOwner()->GetName());
}
}void AGun::PullTriggerMethod()
{
if (!MuzzleFlash) { return; }
UGameplayStatics::SpawnEmitterAttached(MuzzleFlash, Mesh, TEXT(“MuzzleFlashSocket”));
}
And In my Header file
UPROPERTY(EditAnywhere)
UParticleSystem* MuzzleFlash = nullptr;