Load a data table dynamically from C++

Hey, so I’m going to be working with UDataTable a lot and I understand how it all works now.

If it’s possible, how would I load a DataTable blueprint from C++ without using a ConstructorHelpers::FObjectFinder etc.?

ALSO, small thing, how do I access the row name of a struct that extends FTableRowBase e.g.

FMyDataStruct* someData = myDataTable->FindRow<FMyDataStruct>(...);
someData->rowName

Just make EditAnywhere or EditDefaultsOnly UPROPERTY of UDataTable* and then set it in property editor inside blueprint based of that class in “Class Defaults”

Since you placed FMyDataStruct in to template FindRow should automatically cast it to that structure

Well I won’t have a blueprint of that class. I just need something that can load a blueprint without needing to be done within the constructor

.h

FORCEINLINE UDataTable* LoadObjFromPath(const FName& Path)
{
	if (Path == NAME_None) return NULL;

	return Cast<UDataTable>(StaticLoadObject(UDataTable::StaticClass(), NULL, *Path.ToString()));
}

.cpp

LoadObjFromPath(TEXT(“PATHDIR”));

Puede buscar sobre eso

FDTRH_Systems()
: DataTable(nullptr)
, RowName(NAME_None)
{

		UDataTable* DT;
		FSoftObjectPath UnitDataTablePath = FSoftObjectPath(TEXT("/Game/DATA/Blueprints/DataTables/DT_SystemData.DT_SystemData"));
		DT = Cast<UDataTable>(UnitDataTablePath.ResolveObject());

		if (DT)
		{
			DataTable = DT;
		}
		else DT = Cast<UDataTable>(UnitDataTablePath.TryLoad());
		if (DT)
		{
			DataTable = DT;
		}
}
2 Likes

Wow, not worked on this project for a while but thanks :smiley: