Hello,
I’m having some trouble getting C++ inherited components exposed to blueprints where they are editable in the details tab.
Through searching, I have learned how to expose inherited components to blueprints and have them be editable. However, I’m having problems only when the component is declared in another component, and not declared in the actor itself.
Here’s the scenario:
- I create a C++ actor AFooActor, inherited from AActor.
- I create a C++ component UBarSceneComponent, inherited from USceneComponent.
- In AFooActor, I declare a USkeletalMeshComponent FooMesh, and a UBarSceneComponent BarScene.
- In UBarSceneComponent, I declare another USkeletalMeshComponent BarMesh.
- In both AFooActor and UBarSceneComponent’s constructors, I instantiate the above components using CreateDefaultSubobject.
- Finally, I create a blueprint BP_Foo, inherited from AFooActor.
In this case, when I open BP_Foo in the blueprint editor, I would expect FooMesh, BarScene, and BarMesh all to be exposed and editable with the details tab. However, only FooMesh and BarScene, which are declared directly in the actor, are editable. BarMesh, which is declared in UBarSceneComponent and not in the actor, is not editable.
Below are screenshots and code to illustrate.
AFooActor
// Header
#pragma once
#include "CoreMinimal.h"
#include "GameFramework/Actor.h"
#include "FooActor.generated.h"
UCLASS()
class MYAPPLICATION_API AFooActor : public AActor
{
GENERATED_BODY()
public:
AFooActor();
AFooActor(const FObjectInitializer& ObjectInitializer);
public:
// Declare FooMesh
UPROPERTY(VisibleAnywhere, BlueprintReadWrite, Category = "Foo")
class USkeletalMeshComponent* FooMesh;
// Declare BarScene
UPROPERTY(VisibleAnywhere, BlueprintReadWrite, Category = "Foo")
class UBarSceneComponent* BarScene;
};
// Constructor
AFooActor::AFooActor(const FObjectInitializer& ObjectInitializer) : Super(ObjectInitializer)
{
// Works; FooMesh is visible in the blueprint, and the details panel is fully exposed and editable
this->FooMesh = ObjectInitializer.CreateDefaultSubobject<USkeletalMeshComponent>(this, TEXT("FooMesh"));
this->BarScene = ObjectInitializer.CreateDefaultSubobject<UBarSceneComponent>(this, TEXT("BarScene"));
}
UBarSceneComponent
// Header
#pragma once
#include "CoreMinimal.h"
#include "Components/SceneComponent.h"
#include "BarSceneComponent.generated.h"
UCLASS(ClassGroup = (FooBar), meta = (BlueprintSpawnableComponent))
class MYAPPLICATION_API UBarSceneComponent : public USceneComponent
{
GENERATED_BODY()
public:
UBarSceneComponent();
UBarSceneComponent(const FObjectInitializer& ObjectInitializer);
public:
// Declare BarMesh
UPROPERTY(VisibleAnywhere, BlueprintReadWrite, Category = "Bar")
class USkeletalMeshComponent* BarMesh;
};
// Constructor
UBarSceneComponent::UBarSceneComponent(const FObjectInitializer& ObjectInitializer) : Super(ObjectInitializer)
{
// NOT editable; I can see BarMesh in the blueprint, but the details panel is empty and cannot be edited
this->BarMesh = ObjectInitializer.CreateDefaultSubobject<USkeletalMeshComponent>(this, TEXT("BarMesh"));
}
Screenshots of the BP_Foo blueprint are attached. FooMesh and BarScene are exposed and editable. BarMesh is exposed, but not editable.
So my question is, what is the best way to have components declared within components be editable in the blueprint just like those declared in the actor? Is what I’m trying to do possible? I suspect I have some fiddling to do with the UPROPERTY fields, but so far I haven’t found a solution.
Any help is appreciated. Thanks in advance.