Developer_Bastian

Unreal Engine - Load DataTable

Jan 10th, 2024 (edited)
171
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.09 KB | Gaming | 0 0
  1. // Developer Bastian © 2024
  2. // License Creative Commons DEED 4.0 (https://creativecommons.org/licenses/by-sa/4.0/deed.en)
  3. // Tutorial video at https://youtu.be/le4VYlJXASg
  4. // Part of an Unreal Basics video tutorial series at: https://bit.ly/Unreal_Basics_en
  5.  
  6. bool ABA_DataLoader::LoadDataTable(FString Path)
  7. {
  8.     // Loading a DataTable
  9.     if (!Path.IsEmpty())
  10.     {
  11.         UDataTable* tDataTable;
  12.         FSoftObjectPath DTPath = FSoftObjectPath(Path);
  13.         tDataTable = Cast<UDataTable>(DTPath.ResolveObject());
  14.         if (!tDataTable) {
  15.             tDataTable = Cast<UDataTable>(DTPath.TryLoad());
  16.             UE_LOG(LogTemp, Warning, TEXT("BA_DataLoader: Need to use slow LoadObject to load DataTable"));
  17.         }
  18.         if (tDataTable)
  19.         {
  20.             this->ConnectionsDT = tDataTable;
  21.             UE_LOG(LogTemp, Log, TEXT("BA_DataLoader: Successfully loaded Connections DataTable '%s'"), *Path);
  22.             return true;
  23.         }
  24.         else
  25.         {
  26.             UE_LOG(LogTemp, Error, TEXT("BA_DataLoader: Error loading Connections DataTable '%s'"), *Path);
  27.             return false;
  28.         }
  29.     }
  30.     UE_LOG(LogTemp, Error, TEXT("BA_DataLoader: No path specified to load DataTable"));
  31.     return false;
  32. }
Add Comment
Please, Sign In to add comment