Blockquote
AActor::AddComponentByClass()
, followed byAActor::FinishAddComponent()
I second this. I found it’s important to be aware of bDeferredFinish
and that some component’s may need special initialization prior to InitializeComponent()
.
For example, attempting to AddComponentByClass()
without bDeferredFinish == true
for UPhysicalAnimationComponent
will lead to UPhysicalAnimationComponent::InitComponent()
but the UPhysicalAnimationComponent::SkeletalMeshComponent
is not yet set. And InitComponent()
is private so it cannot be called elsewhere. This lead to the game freezing and never crashing.
There is also AActor::AddComponent()
which takes a UObject and appears to duplicate it, but I think the Add+FinishAdd method is cleaner.