Description

UGameplayStatics::SpawnEmitterAttached will keep relative position when using SnapToTarget.

Steps to Reproduce
  1. Create new C++ (First Person or Third Person template) Project, named "AH467216", with Starter Content.
  2. Create new C++ Actor class named: MyActor_Ball
    #pragma once
    
    #include "GameFramework/Actor.h"
    #include "MyActor_Ball.generated.h"
    
    UCLASS()
    class AH467216_API AMyActor_Ball : public AActor
    {
    	GENERATED_BODY()
    	
    public:	
    	AMyActor_Ball();
    	
    	UStaticMeshComponent *Mesh;
    	UChildActorComponent *Child;
    	
    	float CurrentParticleSystemSpawnTime;
    	
    	UParticleSystem *Template;
    };
    
    #include "AH467216.h"
    #include "MyActor_Ball.h"
    
    #include "MyActor_BallChild.h"
    
    AMyActor_Ball::AMyActor_Ball()
    {
    	PrimaryActorTick.bCanEverTick = true;
    
    	Mesh = CreateDefaultSubobject<UStaticMeshComponent>( TEXT("Mesh") );
    	Mesh->SetSimulatePhysics( true );
    	SetRootComponent( Mesh );
    
    	Child = CreateDefaultSubobject<UChildActorComponent>( TEXT("Child") );
    	Child->SetChildActorClass( AMyActor_BallChild::StaticClass( ) );
    	Child->SetupAttachment( RootComponent );
    
    	static ConstructorHelpers::FObjectFinder<UStaticMesh> MeshAsset( TEXT("StaticMesh'/Game/StarterContent/Props/MaterialSphere.MaterialSphere'") );
    	if ( MeshAsset.Succeeded( ) )
    	{
    		Mesh->SetStaticMesh( MeshAsset.Object );
    	}
    
    	static ConstructorHelpers::FObjectFinder<UParticleSystem> TemplateAsset( TEXT("ParticleSystem'/Game/StarterContent/Particles/P_Explosion.P_Explosion'") );
    	if( TemplateAsset.Succeeded( ) )
    	{
    		Template = TemplateAsset.Object;
    	}
    }
    
    void AMyActor_Ball::Tick( float DeltaTime )
    {
    	if( Template )
    	{
    		CurrentParticleSystemSpawnTime += DeltaTime;
    		if( CurrentParticleSystemSpawnTime > 3.5f )
    		{
    			UGameplayStatics::SpawnEmitterAttached(Template,Mesh, NAME_None, Mesh->GetComponentLocation( ), Mesh->GetComponentRotation( ), EAttachLocation::SnapToTarget, true );
    			CurrentParticleSystemSpawnTime = 0.f;
    		}
    	}
    	Super::Tick( DeltaTime );
    }
    
  3. Compile the game project.
  4. Place a MyActor_Ball from the C++ Classes folder into the world.
  5. PIE and run into the MyActor_Ball in the world to get it to roll.

RESULT:

When the Particle System is created with SpawnEmitterAttached( ) using SnapToTarget, targeted at the root component, it keeps relative position instead of taking on the location of the root component.

EXPECTED:

SnapToTarget forces position of the Particle System to the target component.

Have Comments or More Details?

Head over to the existingAnswerHub thread and let us know what's up.

0
Login to Vote

Fixed
ComponentGameplay
Affects Versions4.114.12.5
Target Fix4.14
Fix Commit3121472
Main Commit3136620
CreatedAug 10, 2016
ResolvedSep 12, 2016
UpdatedApr 27, 2018