UWidgetComponent未在Blueprint编辑器中显示详细信息

时间:2017-02-09 09:59:50

标签: c++ unreal-engine4

为什么在蓝图编辑器中没有任何overheadDialogueWidgetComponent详细信息可供编辑?

头:

class ABasePaperCharacter : public APaperCharacter
{
    GENERATED_BODY()
private:
    UDialogueComponentWrapper* dialogueComponentWrapper;
...

CPP:

ABasePaperCharacter ::ABasePaperCharacter ()
{
    this->dialogueComponentWrapper = NewObject<UDialogueComponentWrapper>();
    this->dialogueComponentWrapper->SetUpDialogueComponents(FObjectInitializer::Get(), this->GetRootComponent());
...

头:

UCLASS()
class UDialogueComponentWrapper : public UObject
{
    GENERATED_BODY()    
public:
    void SetUpDialogueComponents(const FObjectInitializer& objectInitializer, USceneComponent* componentToAttachTo);
private:
    UPROPERTY(Instanced, EditAnywhere, BlueprintReadWrite, Category = "Dialogue", Meta = (AllowPrivateAccess = true))
    UOverheadDialogueWidgetComponent* overheadDialogueWidgetComponent;

...

CPP:

void UDialogueComponentWrapper::SetUpDialogueComponents(const FObjectInitializer& objectInitializer, USceneComponent* componentToAttachTo)
{
    this->overheadDialogueWidgetComponent = objectInitializer.CreateDefaultSubobject<UOverheadDialogueWidgetComponent>(objectInitializer.GetObj(), TEXT("Dialogue widget component"));
    this->overheadDialogueWidgetComponent->AttachToComponent(componentToAttachTo, FAttachmentTransformRules::KeepRelativeTransform);
}

头:

UCLASS()
class ECDD_API UOverheadDialogueWidgetComponent : public UWidgetComponent
{
    GENERATED_BODY()    
};

enter image description here

2 个答案:

答案 0 :(得分:0)

由于您将此组件公开给蓝图,因此它不应该是私有的。它们必须受到保护或公开才能暴露给BP(您仍然可以从代码中使用它们)。想象一下BP将APaperCharacter作为父类。 UE将创建它自己的APaperCharacter派生的C ++类,并试图向您展示它自己的属性。由于您的组件是私有的,因此生成的类没有看到它,因此它在“详细信息”面板中不可见。

我相信UE也会在C ++编译期间警告你,标有UPROPERTY(..)的字段不应该是私有的。

答案 1 :(得分:0)

警告,这里没有答案,只有失败......

<强> ABasePaperCharacter:

UCLASS()
class ECDD_API ABasePaperCharacter : public ABasePaperCharacter
{
    GENERATED_BODY()
public:
    ABasePaperCharacter()
    {
        this->dialogueComponentWrapper = CreateDefaultSubobject<UDialogueComponentWrapper>(TEXT("Dialogue component wrapper"));
        this->dialogueComponentWrapper->AttachToComponent(this->GetCapsuleComponent(), FAttachmentTransformRules::KeepRelativeTransform);
        this->dialogueComponentWrapper->SetUpDialogueComponents(FObjectInitializer::Get(), this->dialogueComponentWrapper);
    }
private:
    UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Dialogue", Meta = (AllowPrivateAccess = true))
        UDialogueComponentWrapper* dialogueComponentWrapper;
}

UDialogueComponentWrapper - 注意USceneComponent继承:

UCLASS()
class UDialogueComponentWrapper : public USceneComponent
{
    GENERATED_BODY()
public:
    UDialogueComponentWrapper();
    void SetUpDialogueComponents(const FObjectInitializer& objectInitializer, USceneComponent* componentToAttachTo)
    {
        this->overheadDialogueWidgetComponent = objectInitializer.CreateDefaultSubobject<UOverheadDialogueWidgetComponent>(objectInitializer.GetObj(), TEXT("Dialogue widget component"));
        this->overheadDialogueWidgetComponent->AttachToComponent(componentToAttachTo, FAttachmentTransformRules::KeepRelativeTransform);
    }
private:
    UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Dialogue", Meta = (AllowPrivateAccess = true))
        UOverheadDialogueWidgetComponent* overheadDialogueWidgetComponent;
};

<强> UOverheadDialogueWidgetComponent:

UCLASS()
class ECDD_API UOverheadDialogueWidgetComponent : public UBaseWidgetComponent
{
    GENERATED_BODY()
};

以上所有结果都是这样的:

enter image description here enter image description here

我仍然遇到组件未在其详细信息面板中显示详细信息的问题,但至少我现在可以更改详细信息。

我仍然不知道为什么我在细节面板中看不到组件的属性......但至少我可以继续制作我的游戏。