Blank Details Pane in UE4(C++ HELP)

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.

You’re missing the type of subobject.
BaseMesh = CreateDefaultSubobject(TEXT(“BaseMesh”));

Unless there’s an overload I wasn’t aware of.

You’d also have to expose that in the header file if you want any details.
UPROPERTY(VisibleAnywhere)
UStaticMeshComponent* BaseMesh;

Doug

apparently the forum is editing out the brackets with the type eh?
I just noticed they are inherited in the editor screenshot so disregard this part.

BaseMesh = CreateDefaultSubobject<UStaticMeshComponent>(TEXT("BaseMesh"));

Also, if you haven’t look at the Battle Tank GitHub for example of just this.

Oh, and the UPROPERTY is needed above each new variable you want to expose.
So you should have that line a total of 4 times. This is the main reason, besides the “class” typo I indicate below.

and you have a “class” below UPROPERTY that shouldn’t be there.

That would make it compile actually. It acts as a forward declaration, it’s only needed once in the file and can be done in line like that.

@Joe_H I’ve edited your post to use a code block instead of quotes so <this> is shown. Try closing Unreal and rebuild.

So. I’m correct about UPROPERTY being the main issue?, wrong about class… and learned an inline option. Cool.

OMG! I can’t believe I looked at the code for hours and missed the adding the UPROPERTIES to the other static mesh components!

Thanks for you help…that fixed the issue.

thought you might slap your head when you got back here.

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.

Privacy & Terms