Engine version: 4.27.2
Hi! I’m currently working on a game where I have data tables that stores information about various things in the game. In the code I have softpointers pointing to those data tables. To make sure those pointers actually point to an asset I have written an assertion in the function that gets the datatable.
Now, The problem is that even though I have set those assets inside the editor, it crashes when I try to run the project, which it shouldn’t. I’m at a complete loss as to why and hope someone can illuminate where the problem may lie. Here’s some information on what I have:
(The softptr is stored inside of a custom gameinstance.)
Here’s the declaration of the variable inside the game instance .h file:
UPROPERTY(EditDefaultsOnly, Category = "Data Table References")
TSoftObjectPtr<UDataTable> AllItemsDataTableRef;
Here’s the function that loads and returns the datatable inside the .cpp file. With my assertion at the top. I have also tried using != nullptr instead of IsValid()
UDataTable* UMainGameInstance::GetAllItemsDataTable() const
{
checkf(AllItemsDataTableRef.IsValid(), TEXT("'AllItemsDataTableRef' has no asset referenced, make sure you create and reference an items data table."));
UE_LOG(MainGameInstanceLog, Display, TEXT("AllItemsDataTableRef was found.. Returning it."));
return Cast<UDataTable>(AllItemsDataTableRef.LoadSynchronous());
}
Here’s the table asset being referenced inside the editor:
Am I missing something about how assertions work? From what I understand it checks if the condition is false and then halts the processing. The condition .IsValid() should return true based on my setup but it doesn’t.
Thanks