UGameplayStatics::SpawnEmitterAttached will keep relative position when using SnapToTarget.
#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 ); }
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.
Head over to the existing Questions & Answers thread and let us know what's up.
0 |
Component | UE - Gameplay |
---|---|
Affects Versions | 4.11, 4.12.5 |
Target Fix | 4.14 |
Fix Commit | 3121472 |
---|---|
Main Commit | 3136620 |
Created | Aug 10, 2016 |
---|---|
Resolved | Sep 12, 2016 |
Updated | Apr 27, 2018 |