x

Search in
Sort by:

Question Status:

Search help

  • Simple searches use one or more words. Separate the words with spaces (cat dog) to search cat,dog or both. Separate the words with plus signs (cat +dog) to search for items that may contain cat but must contain dog.
  • You can further refine your search on the search results page, where you can search by keywords, author, topic. These can be combined with each other. Examples
    • cat dog --matches anything with cat,dog or both
    • cat +dog --searches for cat +dog where dog is a mandatory term
    • cat -dog -- searches for cat excluding any result containing dog
    • [cats] —will restrict your search to results with topic named "cats"
    • [cats] [dogs] —will restrict your search to results with both topics, "cats", and "dogs"

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.
alt text alt text

I will be very happy if you'll help me :)

Product Version: UE 4.15
Tags:
beam_data.png (95.2 kB)
beam_req.png (112.0 kB)
more ▼

asked May 06 '17 at 03:13 PM in C++ Programming

avatar image

J0K3R_12QQ
99 21 25 28

(comments are locked)
10|2000 characters needed characters left
Viewable by all users

1 answer: sort voted first

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 :)

more ▼

answered May 06 '17 at 03:33 PM

avatar image

J0K3R_12QQ
99 21 25 28

(comments are locked)
10|2000 characters needed characters left
Viewable by all users
Your answer
toggle preview:

Up to 5 attachments (including images) can be used with a maximum of 5.2 MB each and 5.2 MB total.

Follow this question

Once you sign in you will be able to subscribe for any updates here

Answers to this question