Unreal 4 C++ 杂记 --- DataTable

  1. 结构:
USTRUCT(BlueprintType)
struct FPlayerAttackMontage : public FTableRowBase {
	GENERATED_USTRUCT_BODY()

	UPROPERTY(EditDefaultsOnly, BlueprintReadOnly, Category = Animation, meta = (AllowPrivateAccess = true))
	class UAnimMontage* MeleeAttackMontage;

	UPROPERTY(EditAnywhere, BlueprintReadOnly)
	int AnimSectionCount;

	UPROPERTY(EditAnywhere, BlueprintReadOnly)
	FString Descrtion;
};
  1. 建立
#include "Engine/DataTable.h"
//下面代码 放构造函数里
static ConstructorHelpers::FObjectFinder<UDataTable> PlayerAttackMontageDataObject(TEXT("DataTable'...'"));
	if (PlayerAttackMontageDataObject.Succeeded()) {
		PunchAttackTable = PlayerAttackMontageDataObject.Object;
}
  1. 寻找:
//DataTable 寻找 FindRow   class UDataTable* PunchAttackTable;
static const FString ContextString(TEXT("Player Attack Montage Context"));
FPlayerAttackMontage* AttackMontage = PunchAttackTable->
FindRow<FPlayerAttackMontage>(FName("d02"), ContextString, true);
if (AttackMontage) {}