Thumper
(Thumper)
1
Normally if I want to add a single subobject I would do this.
// .h
SomeComponentType* aComponent;
// .cpp
aComponent = CreateDefaultSubobject<SomeComponentType>(TEXT("a name"));
But what if I want to add an array that I intend to dynamically add objects to?
Thumper
(Thumper)
2
I created a UStruct that housed a
TArray<SomeComponent*> myCompArray;
Then I made that Ustruct a UPROPERTY(). Instead of using CreateDefaultSubobject to add the object in the constructor, I used
myCompArray.Add(NewObject<SomeComponent>(this));
to add the object outside the constructor. “this” being the UObject it’s attaching to.