0
0

UE5勉強日記-data tableの使用

Posted at

C++でblueprintから作るdata tableは下記のコードで使用できる。

FString TablePath = TEXT("/Script/Engine.DataTable'/Game/Data/DT_Food.DT_Food'");
    UDataTable* DataTable = Cast<UDataTable>(StaticLoadObject(UDataTable::StaticClass(), nullptr, *TablePath));
    if (!DataTable)
    {
        UE_LOG(LogTemp, Warning, TEXT("Failed to load DataTable at %s"), *TablePath);
        return false;
    }
    TArray<FName> RowNames = DataTable->GetRowNames();
	FName RowName = RowNames[index];
	FFoodStruct* FoodItem = DataTable->FindRow<FFoodStruct>(RowName, TEXT("LookupID"));
	if (FoodItem)
	{
		FoodItem->Inventory++
    }

☆data tableはRowNameで一行のデータを特定する。直接インデックスで特定できない。
FindRow(RowName, TEXT("LookupID"));
は特定行を探す関数です。
RowNameは検索キーワードで、 TEXT("LookupID")は問題発生した時に残る記録です。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0