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"

How can I get a particle to spawn in a specific location?

Hey! I am trying to get some barrel smoke into my game. What I have done is I am trying to spawn a particle at the same location where the projectile spawns. The problem is that for some reason, the particle seems to spawn in the middle of the level (always, it never changes spawn location). Anyone know why this could happen? The code worked perfectly earlier on when I was testing it. Highly appreciate any useful answers or input!

 const FRotator SpawnRotation = GetControlRotation();
         // MuzzleOffset is in camera space, so transform it to world space before offsetting from the character location to find the final muzzle position
         const FVector SpawnLocation = GetActorLocation() + SpawnRotation.RotateVector(GunOffset);
         UWorld* const World = GetWorld();
         if (World != NULL)
                 FString debugAmmo = FString::FromInt(wpAmmo);
                 if (SmokeClass != NULL)
                     World->SpawnActor<AOneShotParticle>(SmokeClass, SpawnLocation, SpawnRotation);
                 // spawn the projectile at the muzzle
                 World->SpawnActor<AInstinctProjectile>(ProjectileClass, SpawnLocation, SpawnRotation);
                 GEngine->AddOnScreenDebugMessage(-1, 2.f, FColor::Black, debugAmmo);

Product Version: Not Selected
more ▼

asked Apr 28 '14 at 08:07 PM in C++ Programming

avatar image

174 44 39 48

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

1 answer: sort voted first

Spawn Emitter Attached

Using an actor for a particle is inefficient and will cost you later down the line

Also, your code wont keep the particle attached if the muzzle moves while the particle is still playing, so it wont look quite right :)

use this instead!

     ThePSC, //UParticleSystem*
     FVector(0,0,0), //relative offset 
     FRotator(0,0,0), //relative rotation
     true //auto delete on completion



more ▼

answered Apr 28 '14 at 08:26 PM

avatar image

10.6k 446 345 1088

avatar image Borzi Apr 29 '14 at 02:29 PM

Thank you for your answer! My Unreal Engine is experiencing some crashes and I don't know why, but I will look into this once I get it fixed.

avatar image Borzi Apr 30 '14 at 05:47 PM

Sorry Rama, but I had a small question regarding the SpawnEmitter. It works very well, but how can I deactivate it? I only wanted it to spawn particles for a second or so at a time. Would really appreciated a reply!

avatar image yesNinja Dec 31 '14 at 06:51 AM

Not sure if you ever figured this out but I think the particle system itself can have a lifetime , and then setting that last value to true should destroy it.

(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