quick and easy fix for an AActor child class gotcha

So, the definition of an AActor is “an object that can be placed or spawned in the world.”
This implies that every AActor has a location by default… and if you create a blueprint Actor, it does.
However, if you create a C++ AActor, it doesn’t.

Yes, it’s a question of just adding the equivalent of the following to your constructor…

USceneComponent* SceneComponent = CreateDefaultSubobject<USceneComponent>(TEXT("GivesMeAnActualLocation"));
RootComponent = SceneComponent;

… but if you’re just thinking “I need something quick that exists in the world, but doesn’t really do anything special”, it’s easy to overlook this and then you run into all kinds of bizarre edge cases that can take hours to debug.

Condensed version: “please add a root scene component to the default AActor child template”
People can replace the lines in a second if they don’t need them, and if they’re new or are flying through a quick prototype, they won’t run into gotchas.

You’re a few days too late… for me :slight_smile:
Had this exact issue earlier last week.
Fixed it in the exact same way and thought the exact same thing.

They use actors that dont have location and are not considered for rendering all throughout the gameframework. Such as AGameMode etc. So I think that is why AActors dont have scene components by default.

I don’t mean for the AActors themselves to have one, I understand why they’re not part of it by default.
I just meant for the default template that is created when you add a C++ AActor child from inside UE to have one by default in its constructor. If you don’t need it, you can easily delete the two lines of text - but given the average usecase, most people will probably need some kind of scenecomponent child as their root component for their own AActor children?

Ah makes sense

I would like to have game mode type AActor for blueprint, without location.