How do you use FDataTableRowHandle and FindRow

Hello i’ve been searching trying to find examples of how to use FDataTableRowHandle to read data from a data table but non of the few sources i’ve found actually use FDataTableRowHandle, could some one please post a example of how to read data from a data table using FDataTableRowHandle or a more indepth guide on how to do it, because every time i attempted the method shown in the sources below i’ve broken my project.

sources i’ve look at

Hey Devin Sherry thank you for your ansewer, so i tryed to follow your example but it does not seem to be working im trying to get the data from with in a character class and it compiles with out a problem but when i press play the engine crashes and gives a, unhandled exception: exception_access_violation reading address 0x0000000000000030 error

heres a example of my code
in player.h
UFUNCTION(BlueprintCallable)
FString Descript();

UPROPERTY(EditAnywhere)
UDataTable *Handler;
UPROPERTY(EditAnywhere)
FName Row;
UPROPERTY(EditAnywhere)
FString ContextString;

in player.cpp
APlayerCharacter::APlayerCharacter(){
Row = “2”;
ContextString = “”;
}

FString APlayerCharacter::Descript() {
if (Handler) {
FVDT* Table = Handler->FindRow(Row, ContextString);
if (Table) {

	}
	return "1";

}
else {
	return "0";
}
return "H";

}

i have also tryed
FString APlayerCharacter::Descript() {
FVDT* Table = Handler->FindRow(Row, ContextString);
}

Here is a snippet of code from my personal project:

if (WeatherData)
{
	
	FName WeatherRowName = UEnum::GetValueAsName(InitWeather);
	EGetByNameFlags Flags = EGetByNameFlags::None;
	FString NameString = FString::FromInt(StaticEnum<EWeather>()->GetIndexByName(WeatherRowName, Flags));

	if (Flags != EGetByNameFlags::ErrorIfNotFound)
	{
		FWeather* WeatherRow = WeatherData->FindRow<FWeather>(FName(*NameString), "", true);

		if (WeatherRow)
		{
			InitializeWeatherStruct(WeatherRow);
		}
	}

}

Some information about the variables used:

InitWeather - This is a custom Enum variable of type EWeather as shown below:

UENUM(BlueprintType)
enum class EWeather : uint8
{
	SUNNY = 0 UMETA(DisplayName = "Sunny"),
	CLOUDY = 1 UMETA(DisplayName = "Cloudy"),
	RAINY = 2 UMETA(DisplayName = "Rainy"),
	THUNDER = 3 UMETA(DisplayName = "Thunder"),
	NEWWEATHER = 4 UMETA(DisplayName = "NewWeather")
};

FWeather - This is a custom struct derived from FTableRowBase as shown below:

USTRUCT(BlueprintType)
struct FWeather : public FTableRowBase
{
	GENERATED_BODY()

	//Type of weather based off of EWeather enum type.
	UPROPERTY(EditAnywhere, BlueprintReadWrite)
	EWeather WeatherType;

	//
	UPROPERTY(EditAnywhere, BlueprintReadWrite)
	int WeatherWeight;

	//
	UPROPERTY(EditAnywhere, BlueprintReadWrite)
	class UMaterialInstance* WeatherMaterialInstance = nullptr;

	//Color curve used for the sun.
	UPROPERTY(EditAnywhere, BlueprintReadWrite)
	class UCurveLinearColor* WeatherSunColor = nullptr;

	//Color curve for the skylight
	UPROPERTY(EditAnywhere, BlueprintReadWrite)
	class UCurveLinearColor* WeatherSkyLightColor = nullptr;

	//Color curve for the fog.
	UPROPERTY(EditAnywhere, BlueprintReadWrite)
	class UCurveLinearColor* WeatherFogColor = nullptr;

	//Color curve general/atmosphere color.
	UPROPERTY(EditAnywhere, BlueprintReadWrite)
	class UCurveLinearColor* WeatherOverallColor = nullptr;

	UPROPERTY(EditAnywhere, BlueprintReadWrite)
	TArray<FWeatherScalarParamOverride> ScalarParamOverride;

	UPROPERTY(EditAnywhere, BlueprintReadWrite)
	bool bSunVisible;

	FWeather()
	{
		WeatherType = EWeather::SUNNY;
		WeatherWeight = 1;
		bSunVisible = true;
	}
};

WeatherData - This is a UDataTable variable that uses the same FTableRowBase as FWeather:

UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Weather")
UDataTable* WeatherData;

What the original snippet of code does is check whether or not the WeatherData UDataTable parameter is valid and contains the appropriate data table. Then, we attempt to get the name of the row represented by the current value of InitWeather by using the function UEnum::GetValueAsName, and we also initialize an EGetByNameFlags value that is returned GetIndexByName(); this tells us if the index is valid or not. As long as Flags != EGetByNameFlags::ErrorIfNotFound, then we continue. From there, we use FindRow from our data table variable, checking for FWeather struct and pass in the NameString, an empty Context String, and true for the parameter bWarnIfRowMissing. Lastly, we do one more valid check for WeatherRow and then move on; WeatherRow being our found Row.

Here is a thread that helped me out when originally writing this code: Get Data Table Row in c++

I hope this helps, and good luck :slight_smile:

2 Likes

I wanna know if this is fixed. I am brain f@(ked by UDataTable. For now, I am using blueprints as Implementable. It shows same read access violation. Here’s my latest code with Enum and Strings corrected and checked properly:


FMovementParameter UULib::CalculateSpeed(UDataTable* movementTable, EStances stance,
	EFootplacements footCondition, EWeaponary weaponCondition, EMood mood)
{
	FMovementParameter result = FMovementParameter::FMovementParameter();

	// Stance:
	FMovementParameter* stanceParameter = movementTable->FindRow<FMovementParameter>(UEnum::GetValueAsName(stance), "", true);
	FName stanceParameterName = UEnum::GetValueAsName(stance);
	stanceParameter = movementTable->FindRow<FMovementParameter>(stanceParameterName, "", true);

	// Foot:
	FMovementParameter* footParameter = movementTable->FindRow<FMovementParameter>(UEnum::GetValueAsName(footCondition), "", true);
	FName footParameterName = UEnum::GetValueAsName(footCondition);
	footParameter = movementTable->FindRow<FMovementParameter>(FName(footParameterName), "", true);

	// WeaponParameter:
	FMovementParameter* weaponParameter = movementTable->FindRow<FMovementParameter>(UEnum::GetValueAsName(weaponCondition), "", true);
	FName weaponParameterName = UEnum::GetValueAsName(weaponCondition);
	weaponParameter = movementTable->FindRow<FMovementParameter>(FName(weaponParameterName), "", true);

	// Mood
	FMovementParameter* moodParameter = movementTable->FindRow<FMovementParameter>(UEnum::GetValueAsName(mood), "", true);
	FName moodParameterName = UEnum::GetValueAsName(mood);
	moodParameter = movementTable->FindRow<FMovementParameter>(FName(moodParameterName), "", true);


	UULib::PrintMessaged(FString::SanitizeFloat(stanceParameter->uSpeed), 10.0f);
	UULib::PrintMessaged(FString::SanitizeFloat(footParameter->uSpeed), 10.0f);
	UULib::PrintMessaged(FString::SanitizeFloat(weaponParameter->uSpeed), 10.0f);
	UULib::PrintMessaged(FString::SanitizeFloat(moodParameter->uSpeed), 10.0f);

	result.uSpeed = stanceParameter->uSpeed * footParameter->uSpeed * weaponParameter->uSpeed * moodParameter->uSpeed;
	result.uHeight = stanceParameter->uHeight;
	result.uStaminaLoss = stanceParameter->uStaminaLoss * weaponParameter->uStaminaLoss * moodParameter->uStaminaLoss ;
	result.uCameraFOV = stanceParameter->uCameraFOV * footParameter->uCameraFOV * weaponParameter->uCameraFOV * moodParameter->uCameraFOV;
	result.uCameraShake = stanceParameter->uCameraShake * footParameter->uCameraShake * weaponParameter->uCameraShake;

	return result;
}

Edit:
I don’t understand WTF read access violation comes to do. I tried Administrator permissions on. Still same. Unreal Engine crashes :frowning: with read access violation.