Warning: None of them were set as the actor's RootComponent

Sorry if this is a silly question, I’m fairly new to gamedev and UE4 and cant seem to spot the issue. I’m spawning an actor on my level and I’m getting the following warning in my logs:

LogActor:Warning: MyTower_C /Game/TopDownCPP/Maps/UEDPIE_0_TopDownExampleMap.TopDownExampleMap:PersistentLevel.MyTower_C_3 has natively added scene component(s), but none of them were set as the actor's RootComponent - picking one arbitrarily

I’m spawning the actor from a separate class like so:

	FActorSpawnParameters spawnParams;
	spawnParams.Owner = this;
	spawnParams.Instigator = Instigator;

	ATower* newTower = GetWorld()->SpawnActor<ATower>(Tower, TraceHitResult.Location, FRotator(0.0f), spawnParams);

Tower.cpp

#include "TowerWars.h"
#include "Tower.h"

ATower::ATower()
{
 	// Set this actor to call Tick() every frame.  You can turn this off to improve performance if you don't need it.
	PrimaryActorTick.bCanEverTick = true;

	//Create mesh component
	TowerMesh = CreateDefaultSubobject<UStaticMeshComponent>(TEXT("TowerMesh"));
	TowerMesh->AttachTo(RootComponent);
}
....

Tower.h

...
	UPROPERTY(EditDefaultsOnly, BlueprintReadOnly, Category=Mesh, meta = (AllowPrivateAccess = "true"))
	UStaticMeshComponent* TowerMesh;
...

Then I create a blueprint (MyTower) from the class and add a mesh with the blueprint. I’m not quite sure if I ever pointed specifically to the BP from the c++ code. Is this what is being picked arbitrarily; If so how would I specify? Or am I looking in the complete wrong direction?

Thanks!

Bump, I also ran in to this today.

Change:

TowerMesh = CreateDefaultSubobject<UStaticMeshComponent>(TEXT("TowerMesh"));
TowerMesh->AttachTo(RootComponent);

To:

TowerMesh = CreateDefaultSubobject<UStaticMeshComponent>(TEXT("TowerMesh"));
 SetRootComponent(TowerMesh);
4 Likes

To be specific: you need to make sure that you’re setting a RootComponent on your actor.

4 Likes