Setting beam emitter source and target on runtime in C++

Hello.
I’m trying to make a laser gun using line trace. I’m spawning particles at the impact point of it and I wanted to add a beam emitter going all the way from the gun to the impact point.
For spawning the particles I used this:

UGameplayStatics::SpawnEmitterAtLocation(World, ImpactParticleSystem, FireHit.ImpactPoint)

Then for setting my target and source I tried this:

UParticleSystemComponent* ImpactParticle = UGameplayStatics::SpawnEmitterAtLocation(World, ImpactParticleSystem, FireHit.ImpactPoint);
ImpactParticle->SetBeamSourcePoint(2, PlayerCamera->GetComponentLocation(), 1);
ImpactParticle->SetBeamTargetPoint(2, FireHit.ImpactPoint, 1);

But it didn’t work.
i think that the particle emitter is spawning before the code is setting the source and the target of the beam.
I know, that there’s a way to do this, but I’ve been searching for it for 2 days and I still cannot find an answer.
Here’s my particle system, it may be useful.

I will be very happy if you’ll help me :slight_smile:

Ok, I did it!
I could just delete this question at this point, but I don’t want to, because like I said I never found a good solution on the internet.
So here’s what you have to do:
just replicate what I did, but:

  1. Add a source and target element to your system and set the target/source method to “User Set”
  2. Change set the emitter index to 1 and source/target index to 0 in ImpactParticle->SetBeamSourcePoint(2, PlayerCamera->GetComponentLocation(), 1); ImpactParticle->SetBeamTargetPoint(2, FireHit.ImpactPoint, 1);
  3. Enjoy!

I hope I helped someone.
btw. Make sure you set the speed of the beam to 0, because I was pretty confused for a second :slight_smile: