How do I register an Actor's component?

I have the following code:

ABaseUnit::ABaseUnit(const class FPostConstructInitializeProperties& PCIP)
	: Super(PCIP)
{
	//Create the component
	MovementComponent = PCIP.CreateDefaultSubobject<UBaseMovementComponent>(this, TEXT("MovementComponent0"));
	//Set it's parameters
	//Movement->Something = ? ;
	//Add component to actor
	AddComponent(FName("MovementComponent0"), false, FTransform(), NULL);

	CollisionComponent = PCIP.CreateDefaultSubobject<USphereComponent>(this, TEXT("CollisionComponent0"));
	CollisionComponent->InitSphereRadius(35.0f);
	CollisionComponent->BodyInstance.bEnableCollision_DEPRECATED = true;

	static FName CollisionProfileName(TEXT("Pawn"));
	CollisionComponent->SetCollisionProfileName(CollisionProfileName);

	CollisionComponent->CanBeCharacterBase = ECB_No;
	CollisionComponent->bShouldUpdatePhysicsVolume = true;

	AddComponent(FName("CollisionComponent0"), false, FTransform(), NULL);
	RootComponent = CollisionComponent;
}

I get this error message when I try to add it to the level in the editor:

D:\BuildFarm\buildmachine_++depot+UE4-Releases+4.1\Engine\Source\Runtime\Engine\Private\LevelActor.cpp(692): Ensure condition failed: PrimComp->IsRegistered()
Components must be registered in order to be used in a ComponentOverlapMulti call. PriComp: CollisionComponent0 TestActor: Default__GameUnit_C

So the probably seems to be the component is not registered. But the documentation says:

ActorComponents are automatically
registered when the owning Actor is
spawned, if they are created as
sub-objects and added to the
Components array in the default
properties of the Actor.

(Unreal Engine のコンポーネント | Unreal Engine 5.3 ドキュメント)

So, why am I getting this error?

#Wiki Tutorial

A new, community-hosted Unreal Engine Wiki - Announcements - Unreal Engine Forums,Making_Native%26_Deferred_Attached_to_Socket

It’s a lot simpler than what you are doing, Enjoy!

Just set the AttachParent to be the root component and that’s all, optionally specifying a socket.

//Deferred Attachment (Ty Nick W.! Actual attach gets done after blueprint stuff)
JoyfulControl->AttachParent = RootComponent;
//JoyfulControl->AttachSocketName = FName(TEXT("JoyControl"));

Rama

Hi Rama,
I’ve just recently attempted your tutorial to add a USphereComponent at runtime to my actor, I get this:

“TSubobjectPtr is deprecated and should no longer be used. PLease use pointers instead”

Any chance your tutorial will be updated to explain how to do this with default pointers? I am a bit of a noob and can’t figure it out :X