This is something I’m doing just to learn unreal C++, but I’m stuck and I’m hoping someone can help. The idea is to create a turret like gun where each part rotates separately but the hierarchy also effects it. Ie: support rotates in Yaw and Gun rotates in pitch but gun should still move in Yaw along with support. (Make Sense?)
I created a New C++ class based on the Actor Class. In my header file I have the following code:
UPROPERTY(VisibleAnywhere, BlueprintReadWrite, Category = "SentryGun")
class UStaticMeshComponent* BaseMesh;
UStaticMeshComponent* SupportMesh;
UStaticMeshComponent* GunMesh;
UStaticMeshComponent* BarrelMesh;
in my .cpp file I have the following include:
#include "Components/StaticMeshComponent.h"
then in my constructor class I placed the following code:
BaseMesh = CreateDefaultSubobject<UStaticMeshComponent>(TEXT("BaseMesh"));
BaseMesh->SetupAttachment(GetRootComponent());
SupportMesh = CreateDefaultSubobject<UStaticMeshComponent>(TEXT("SupportMesh"));
SupportMesh->SetupAttachment(BaseMesh);
GunMesh = CreateDefaultSubobject<UStaticMeshComponent>(TEXT("GunMesh"));
GunMesh->SetupAttachment(SupportMesh);
BarrelMesh = CreateDefaultSubobject<UStaticMeshComponent>(TEXT("BarrelMesh"));
BarrelMesh->SetupAttachment(GunMesh);
The code compiles fine in both VS2019 and Unreal. HOWEVER…
When I click on Base Mesh in my blueprint created from my newly created class I get the normal details panel and can set my Static Mesh, but if I click on any of my other attached objects the details panel is blank! (so i can only set the static mesh for Base Mesh and none of my subobjects)
I’ve tried recreating the blueprint, reloading the asset to no avail…my subobjects have no details in the panel. Did I miss something?!? If anyone has an idea please let me know.
I’ve attached a couple of screen shots so it hopefully makes it more clear what’s going on.