Hi,
My is about how to attach and actor with sub actors via Rootcomponent to other actors.
.h
UPROPERTY(VisibleAnywhere, Category = Effect)
UParticleSystemComponent* ParticleComponent;
.cpp Constructor
TSubobjectPtr<USceneComponent> SceneComponent = PCIP.CreateDefaultSubobject<USceneComponent>(this, TEXT("FXComponent"));
RootComponent = SceneComponent;
TSubobjectPtr<UParticleSystemComponent> ParticleTmp = PCIP.CreateDefaultSubobject<UParticleSystemComponent>(this, TEXT("ParticleComponent"));
ParticleComponent = ParticleTmp;
const ConstructorHelpers::FObjectFinder<UParticleSystem> SpawnFXObj(TEXT("ParticleSystem'/Game/Pickups/Particles/P_Sparks.P_Sparks'"));
ParticleComponent->SetTemplate(SpawnFXObj.Object);
ParticleComponent->SetVisibility(true);
ParticleComponent->AttachParent = RootComponent;
ParticleComponent->SetMobility(EComponentMobility::Movable);
.cpp Init
// This is my own Init function which is called after the object is created by spawnactor
void AG1FX::Init(AActor* InOwner)
{
AttachRootComponentToActor(InOwner, NAME_None, EAttachLocation::SnapToTarget);
}
Problem
The Position of the Rootcomponent is moving with the Actor it snaps to.
The ParticleComponent is not moving.
My solution:
This would require that i attach all components in my class to the other actor which is not very nice.
ParticleComponent->AttachTo(InOwner->GetRootComponent(), NAME_None, EAttachLocation::SnapToTarget);
Question
Is is possible to move the Compoents attached to the Rootcomponent to move with the Rootcomponent?
Maybe i’m missing something…
thx