The CreateDefaultSubobject only work in the constructor. I want dynamically add components in the OnConstruction.
This is the test code of OnConstruction function:
USceneComponent* root = GetRootComponent();
ParticleSystemComponent* MyComponent = NewObject<UParticleSystemComponent>(this);
UParticleSystemComponent* MyComponent1 = NewObject<UParticleSystemComponent>(this);
AddComponent(FName(TEXT("asdf")), false, FTransform::Identity, MyComponent);
AddComponent(FName(TEXT("asdf")), false, FTransform::Identity, MyComponent1);
MyComponent->SetTemplate(Particle);
MyComponent1->SetTemplate(Particle);
SetRootComponent(root);
There have some problem if I doing it like this:
1.The first component always be the root and I can change it although I use SetRootComponent(OtherComponent).
2.I only can add one component to my actor. The second component can not be add.
3.The component always in the origin.
I want to it more like “AddParticleSystemComponent” node in blueprint