How to set up collision for a static mesh assigned at runtime?

I have a static mesh that is assigned at runtime, but it doesn’t have collision even though I set it up for collision in the component. What am I missing? Here is the constructor:

ASPawn_Enemy::ASPawn_Enemy(const FObjectInitializer& ObjectInitializer)
	: Super(ObjectInitializer)
{
	EnemyStaticMesh = ObjectInitializer.CreateDefaultSubobject<UStaticMeshComponent>(this, "Mesh");
	RootComponent = EnemyStaticMesh;

	EnemyStaticMesh->Mobility = EComponentMobility::Movable;
	EnemyStaticMesh->bGenerateOverlapEvents = true;
	EnemyStaticMesh->SetNotifyRigidBodyCollision(true);
	EnemyStaticMesh->SetCollisionProfileName(FName("Enemy"));
}

Seems I should be able to set up collision for the component and assign the mesh later, but it doesn’t work. I also tried calling an UpdateCollision() function after the static mesh gets set, but that didn’t work either. I should also mention that I was using the “Enemy” collision profile before I switched to changing out meshes at runtime and it worked just fine, so I don’t think the collision profile is the problem.

Found the problem. I had to give the class a default static mesh in the constructor. I found updating the collision after changing the mesh is also necessary.

What is means that you give the class a default static mesh in the constructor?

I mean I had to assign a static mesh right when the object was created rather than at a later point. Like this:

##.h

UStaticMeshComponent* EnemyStaticMeshComp;
UStaticMesh* DefaultMesh;

##.cpp

ASPawn_Enemy::ASPawn_Enemy(const FObjectInitializer& ObjectInitializer)
	: Super(ObjectInitializer)
{
	// mesh
	static ConstructorHelpers::FObjectFinder<UStaticMesh> Baddie1(TEXT("StaticMesh'/Game/Pawns/Meshes/baddie1.baddie1'"));

	// setup
	DefaultMesh = Baddie1.Object;

	EnemyStaticMeshComp = ObjectInitializer.CreateDefaultSubobject<UStaticMeshComponent>(this, FName("EnemyMesh1"));
	EnemyStaticMeshComp->StaticMesh = DefaultMesh;
	RootComponent = EnemyStaticMeshComp;
}

If I didn’t give the object a static mesh from the beginning, then I could never assign a new static mesh along with new collision to it later. For the collision to work on the new mesh, I had to give the object a default mesh to start with.