Attaching UParticleSystemComponent to Projectile

Hello,

I have just started learning UE4, and coming from Unity the transition isn’t half bad :slight_smile:

I am attempting to develop a small benchmarking application, if you will.
I have opened the default starting project, First Person Shooter template in Code.

I have altered the needed FPSProjectile header and code to include the following:

FPSTestProjectile.h:

UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = Projectile)
	class UParticleSystemComponent* Particles;

FPSTestProjectile.cpp, within AFPSTestProjectile constructor:

	//Particles!
	Particles = CreateDefaultSubobject<UParticleSystemComponent>(TEXT("Particles"));
	Particles->SetRelativeLocation(FVector::ZeroVector);
	Particles->AttachTo(RootComponent);
	

	static ConstructorHelpers::FObjectFinder<UParticleSystem> ParticlesInAssets(TEXT("ParticleSystem'/Game/FirstPerson/Particles/P_OrbGlowLights2.P_OrbGlowLights2'"));

	Particles->SetTemplate(ParticlesInAssets.Object);

The goal is to have a fancy particle system following the projectile.
I have created a neat particle system like the ones seen in early preview tech demos (lots of swirly random particles around a sphere) using a vector field I obtained from the ParticleEffects demo scene.

Now, as the particle system component is a subobject of the TestProjectile, one would normally assume it would follow it. However this is where wierd stuff starts happening:

In editor, dragging and dropping the TestProjectile into the scene produces expected results - particles are emitted and are following the projectile etc etc.

However as soon as the gameplay mode, or simulate mode is engaged, the particle system always goes to the absolute 0,0,0 coordinates of the world, regardless of it’s parent’s location, or velocity.

Here is where it gets even weirder:

Ejecting from the character and inspecting the Actor (to be precise, it’s particle system component) shows that both the relative and world location (in it’s transform tab) are set to apparently, correct values, however performing this switch world/relative within the Details panel while the game is paused starts teleporting the actor to the particle system, or particle system to the actor, or seperating them again to what they were when I paused the game, or any combination of these events (I guess, in regard to which component did I switch relative/world position view).

What is going on here, how can I have a particle system component simply following the needed Actor?

This specific actor has a USphereComponent set as RootComponent, and it does have a ProjectiveMovement component to it as well. Perhaps that’s influencing it’s physics somewhat?

I have temporarily solved the problem using this:

FPSTestProjectile.css:

void AFPSTestProjectile::Tick(float Delta)
{
	Super::Tick(Delta);
	Particles->SetWorldLocationAndRotation(RootComponent->GetComponentLocation(), RootComponent->GetComponentRotation());
}

The behavior in-game is as expected but this can’t be elegant solution I am looking for, can it? In addition, simply setting the world location and rotation doesn’t actually result in any velocity, which is a shame since the particle system also has it’s particles inherit the emitter’s velocity for additional effect.

You seem to be doing it mostly correctly. One thing that seems off may be this :

     Particles->SetRelativeLocation(FVector::ZeroVector);
     Particles->AttachTo(RootComponent);

I would inverse those two line, since first you want to attach it and THEN you want it to go to relative offset 0,0,0.

  Particles->AttachTo(RootComponent);
 Particles->SetRelativeLocation(FVector::ZeroVector);

Give it a try and let me know if that was your issue!

Mick

Hi,

Unfortunately the result is the same :frowning:
The “SetRelative” line might as well be commented out, it doesn’t appear to be doing anything since the particle system is always at the 0,0,0 of the world (unless manually updated in Tick function).

It’s as if the Particle system component gets ‘unparented’ and reset somewhere around Post Begin Play event. Like I said, while in the Editor, particle system follows the actor nicely as I drag it around, but as soon as the gameplay starts, all particle systems of that actor reset to 0,0,0 and stop following it around (it doesn’t matter if actor was already in the scene, or spawned from a gun afterwards).

I have a copy of that particle system, just with some parameters tweaked and different vector field to act as a snow-like effect over the level. It’s not attached to the projectile actor, it’s just a simple Particle System, and that one’s working perfectly fine.

That’s strange, I can confirm I have PSComponents working correctly with a lot of my actors.

I would then suspect your RootComponent, or the composition of your actor. Whta is the exact hierarchy of your actor component wise?

You can see the hierarchy on the right:

https://drive.google.com/file/d/0B8AdDXW9nCiCSzBaWFl3aVI5bkk/view?usp=sharing

(It’s just a blueprint based off the Projectile class, the blueprint itself is empty, all the code is in C++)

When I press Simulate, or spawn the object from the gun at runtime, the particle system automatically resets to 0,0,0 and doesn’t follow or mimic the actor.

Here’s my code in full:

I’m glad to know my case isn’t an isolated one. I haven’t done any work on this (or anything UE4 related) lately, and my knowledge is quite limited as I’m still only a beginner.

If you happen to find out anything more about this, let me know.

I also experience the same issue and I don’t want to do it in Tick function. Any updates on this?

I’m having the same problems as well. I’ll be on the lookout for fixes.

There is this guy who manages to do it with Blueprints so I assume this is just a bug when Particle System is built via C++. I will have a deeper look into it.

Hmm, I guess my problem is slightly different than this. Whenever I make an actor with a particle system attached, the particle system does not rotate with actor.

I have removed all C++ code and re-created the effect with Blueprints. True, there is no position setting in every Tick function now, but the result is much the same.
Here are a few screenshots:
http://i690.photobucket.com/albums/vv263/Eudaimonium/Game%20screenshots/Particlesystem_zps7xzvqpv1.jpg~original

This is my particle system. Note that it doesn’t have initial velocity, and last entry in list is Inherit velocity from parent.

This is my Projectile blueprint:

You can notice the particle system having a Static mesh parent.

Please do note the behavior in-game:
http://i690.photobucket.com/albums/vv263/Eudaimonium/Game%20screenshots/NoVelocityInheretance_zpsekpymo4n.jpg~original
This is a projectile bouncing off the wall. As you can see, the spawned particles, as soon as they leave the vector field following it’s particle system, are just floating in the air, instead of actually inheriting the parent’s velocity. Expected result would be a swarm of particles following the projectile, and not leaving a trail behind it, so that large number of particles would collide against the wall with lots of velocity as well, resulting in visually nice effect.

I have seen the video of the guy who posted a tutorial up there, he is having the exact same situation, though he may not want to have the velocity inheritance.

I don’t have a force field and the effect is similar. After some tangent value, particle system stops following projectile and deviates from the projectile path, even if there is no collision during the flytime.