Spawn emitter from particle system in assets?

I want to spawn an explosion at a location. I have the reference to the asset: ParticleSystem’/Game/Effects/ParticleSystems/Weapons/RocketLauncher/Impact/P_Launcher_IH.P_Launcher_IH’

How do I go about linking this asset to making it spawn in my game for a period of time without using Blueprints?

Hi Bob,

You can use the method in UGameplayStatics called SpawnEmitterAtLocation to spawn a particle system. There’s plenty examples of other systems doing that in the code if you need more help.

I know about that method. All the other particle systems in code are in things like explosions, which are called after firing a grenade like weapon. I can’t call the particle system directly.
How do I create a new particle system in code and map an already created particle system in assets to it?

Hmm, I don’t quite understand. What do you mean you can’t call the particle system directly and want to map one particle system over another?

You might be able to use something like a Redirector, although that seems a bit scary. I’d just have it use whatever particle system you want instead. If you know the path of the asset you want to use, you can use FStringAssetReference with it’s TryLoad() method to load the particle at runtime.

I’m sorry I’ll try to be as clear as possible.

I have this particle system declared in ShooterCharacter.h:

/** effect played on respawn */
	UPROPERTY(EditDefaultsOnly, Category = Pawn)
	UParticleSystem* RespawnFX;

Right now it is called on respawn like this:

if (RespawnFX)
{
UGameplayStatics::SpawnEmitterAtLocation(this, RespawnFX, GetActorLocation(), GetActorRotation());
}

However it never executes inside the if statement. Am I right in assuming RespawnFX is somehow null? If so, does that mean a particle system is not properly attached to it?
Also how would I go about attaching an effect to the particle system RespawnFX? Thank you.

Respawn FX is likely null if you aren’t seeing anything. You can place a breakpoint and verify. Your code would require a designer or someone is setting that value in the Unreal Editor and then saving it.

What do you mean “attaching an effect”? Do you want to attach another particle to this one you are trying to spawn? Or do you want the RespawnFX attached to some object?

I might be using the wrong terms as I am new to Unreal Engine. I want RespawnFX to be assigned the bazooka effect that I have in my assets. I hope that in doing this then RespawnFX would no longer be null and upon respawn a bazooka effect would play.

Ah, Gotcha. You need to set RespawnFX somehow. Normally you do that through the editor. I assume you have a ShooterCharacter somewhere in your level? Click on it, find the RespawnFX field, and point it to the Bazooka Particle System. Then save and run your game.

You could also force in it code by something like this:
FStringAssetReference BazookaPath(TEXT("/Game/Effects/ParticleSystems/Weapons/RocketLauncher/Impact/P_Launcher_IH"));
RespawnFX = Cast(BazookaPath.TryLoad());

Thank you so much! Remapping it worked. I’ve done so much research on getting this to work.

Yay! Cheers!