[UE 4][V 4.10]C++でUMG widget変数を定義するときのヘッダファイル参照の問題

1913 ワード

以下に、PlayerControllerヘッダファイルなどのUUserWidgetタイプの変数をc++で定義します.
protected:
	/** The widget class we will use as our game over screen when the player wins. */
	UPROPERTY(EditAnywhere, BlueprintReadOnly, Category = "Game")
		TSubclassOf<UUserWidget> VictoryWidgetClass;

	/** The widget instance that we are using as our menu. */
	UPROPERTY()
		UUserWidget* CurrentWidget;

 
ではV 4.10リリースで参照が必要なヘッダファイルは、次のように追加します.
#include "Blueprint/UserWidget.h"

 
以前の古いバージョンでは、次のように追加する必要があります.
#include "Runtime/UMG/Public/UMG.h"
#include "Slate.h"

 
バージョン4.10に上記の2行を追加すると、コンパイルエラーが発生します.
Error C2440 'initializing': cannot convert from 'const char [106]' to 'int'
Error C4430 missing type specifier - int assumed. Note: C++ does not support default-int
 
また、「プロジェクト名.Build.cs」構築構成にUMG、Slate、CoreSlateを追加することも忘れないでください.
PublicDependencyModuleNames.AddRange(new string[] { "Core", "CoreUObject", "Engine", "InputCore", "UMG", "Slate", "SlateCore"});
 
=====================================================
UMG Componentタイプの変数(UBUttonなど)をC++コードで定義する場合は、次のようになります.
UButton* btn = Cast<UButton>(CanvasPanelWidget->GetChildAt(0))

 
 
では、あなたの「エンジニアリング名.h」に次のヘッダファイルを追加する必要があります.
#include "Runtime/UMG/Public/UMG.h"
#include "Runtime/UMG/Public/UMGStyle.h"
#include "Runtime/UMG/Public/Slate/SObjectWidget.h"
#include "Runtime/UMG/Public/IUMGModule.h"
#include "Runtime/UMG/Public/Blueprint/UserWidget.h"

 
 
コンパイルエラーが発生します.
error C2504: 'UContentWidget': base class undefined