I realize this is a really old post, but hoping for some help on this same scenario in UE5. I’m trying to instantiate an array of USplineComponents within BeginPlay(). In my Actor’s .h I declare
public:
UPROPERTY(Instanced)
TArray<USplineComponent*> Splines;
In the Actor’s .cpp
void AMyActor::BeginPlay()
{
...
USplineComponent* spline = CreateDefaultSubobject<USplineComponent>(TEXT("SomeSpline"), false); // tried true here as well
}
When I PIE, UE5 crashes in CoreUObject.dll. I’ve tried subclassing USplineComponent with
UCLASS(EditInlineNew)
class KUIPER_API UInstancedSplineComponent : public USplineComponent
{
GENERATED_BODY()
};
but it still crashes. I don’t need the spline components exposed in the editor, I just need to generate them dynamically during gameplay.
EDIT:
I was able to fix this by using
USplineComponent* spline = NewObject<USplineComponent>(this, TEXT("SomeSpline"));
instead of CreateDefaultSubobject