[Question] How Attach a ParticleSystemComponent to a Character Mesh Without Using GameplayStatics SpawnAttached?

Dear Friends at Epic,

I need to do the following

  • spawn a particle using gameplaystatics spawn at location
  • manually attach this PSC to a Character’s Mesh

I cannot use gameplay statics spawnattached, because I am using vertex locations, not bone or sockets.

So I need to spawn the PSC in world space, and then attach it to the character mesh, keeping relative offset.

I see in shootergame example that a PSC is created and added to the components of the pickup actor, but I am doing this during game time and the number of PSCs is very very large.

#What Works

The PSCs spawn at the correct locations in world space, but they do not become attached and move with the character.

#My Attach PSC To Mesh Function

Here’s what I’ve tried so far:

void AVictoryPlayerCharacterBase::AttachPSCToMesh(UParticleSystemComponent* ThePSC)
{
	if(!ThePSC) return;
	//~~~~~~~~~~
	ThePSC->SetMobility(EComponentMobility::Movable);
	ThePSC->AttachTo(Mesh);
	ThePSC->AttachParent = Mesh;
}

#Goal

How can I spawn in world space and then attach a PSC to a Character Mesh, keeping relative offsets?

Thanks!

Rama

Unless I’m blanking on something (which is possible) won’t this work?

UGameplayStatics::SpawnEmitterAttached(EmitterTemplate, Mesh, NAME_None, Location, Rotation, EAttachLocation::KeepWorldPosition);

I suspect that your issue with using SpawnEmitterAtLocatino is that SetAbsolute(true, true, true) is called on it. Calling PSC->SetAbsolute(false, false, false) before calling AttachTo might be enough to unfix it.

Also keep in mind that the GameplayStatics code calls ActivateSystem so your system will have already activated at the end of the SpawnEmitterAtLocation call, given that you’re leaving it at the same world location/rotation it is probably ok, but something to keep in mind.

Dear Marc,

Thanks Marc!

Very nice to hear from you!

I eventually solved my problem by realizing I needed to use spawn emitter attached, but convert my World Space location into the Mesh’s local space.

I used InverseTransformPosition to accomplish this:

//RV_Vect = the World Space Position I want the Emitter to show up at
//MeshTransform acquired by Mesh->GetComponentToWorld();
AV_MeshTransform.InverseTransformPosition(RV_Vect)