I’m trying to create an APawn subclass in C++, because I’m going to do more math than would be comfortable in blueprint.
I’d like this Pawn to have a hierarchy of static mesh components: Body -> Femur -> Tibia -> Metatarsal.
(Actually, there are more Femurs, etc; one chain per leg.)
I do NOT want to do this as a skinned mesh; I want to define a separate mesh for each.
Now, I’ve set up the APawn with a number of properties:
UPROPERTY(EditAnywhere, BlueprintReadWrite)
UStaticMeshComponent *Root;
UPROPERTY(EditAnywhere, BlueprintReadWrite)
UStaticMeshComponent *Body;
UPROPERTY(EditAnywhere, BlueprintReadWrite)
UStaticMeshComponent *FrontLeftFemur;
UPROPERTY(EditAnywhere, BlueprintReadWrite)
UStaticMeshComponent *FrontLeftTibia;
....
I then create the Root and the different components as follows:
(inside the constructor, taking an FObjectInitializer):
Root = OI.CreateAbstractDefaultSubobject<UStaticMeshComponent>(this, TEXT("Root"));
RootComponent = Root; // for AActor
Root->SetupAttachment(nullptr, TEXT("Root"));
Body = NewObject<UStaticMeshComponent>(this, L"Body");
Body->AttachToComponent(Root, FAttachmentTransformRules::KeepRelativeTransform, L"Body");
Body->RegisterComponent();
FrontLeftFemur = MakeLegBone(BodyMesh, L"FrontLeftFemur");
FrontLeftTibia = MakeLegBone(LegLeftUpper, L"FrontLeftTibia");
.....
The MakeLegBone function does this:
UStaticMeshComponent *AStompyRobotPawn::MakeLegBone(UStaticMeshComponent *Parent, FName const &Name)
{
UStaticMeshComponent *ret = NewObject<UStaticMeshComponent>(this, Name);
ret->AttachToComponent(Parent, FAttachmentTransformRules::KeepRelativeTransform, FName(Name));
ret->RegisterComponent();
ret->bCreatedByConstructionScript_DEPRECATED = true;
ret->bAllowAnyoneToDestroyMe = true;
return ret;
}
I can create a blueprint subclass of this object, call it BP_Pawn, and then open it up.
First, it doesn’t open with a Viewport, so I have to click the “open full blueprint editor” to get there.
Second, when I try to save, I get the error:
I think I’m perhaps on the right way, but there are specifics about how to create these components to make them show up properly in the blueprint editor, and then be able to save them.
What am I missing here? I’ve read the documentation for the APawn and UStaticMeshComponent classes, but they aren’t particularly helpful with the “why” of the outer surroundings.
What’s a good link for the surrounding environment knowledge I need to have to move forward with this?