Questions about creating and using a custom Actor class

I was able to answer my own questions.

  1. I found out that if I don’t set the root component explicitly, AActor will set one of the scene components as root automatically in AActor::FixupNativeActorComponents(). That explains the behavior I was getting.

  2. I was able to fix this error by creating the spline component using CreateDefaultSubobject instead of NewObject. I don’t know understand what’s going on because I didn’t find documentation about this but it worked so…



ARoad::ARoad( const FObjectInitializer& ObjectInitializer ) {
    // 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 the spline component and set it as the root component.
    SplineComponent = ObjectInitializer.CreateDefaultSubobject<USplineComponent>(this, FName(TEXT("Spline")));
    SplineComponent->SetMobility(EComponentMobility::Static);
    SetRootComponent(SplineComponent);
}


  1. I found out I need to set the variable’s UPROPERTY with BlueprintReadWrite. Here’s an example:


UPROPERTY(EditAnywhere, BlueprintReadWrite, Category=RoadSetup)
UStaticMesh* DefaultStaticMesh;