How to load data table checking using bool? C++

Hi, I want to achieve this for optimization purpose.


we can do something like to load data.

if (const UDataTable* Datas = LoadObject<UDataTable>(GetWorld(), TEXT("/Game/Data/MyDatatable")))
    {
    //logics
    }

so if statement is loading the datatable and checking for null ptr at the same time, I want to do something same but using bool which is in my control.


why we can’t do something like this? or something more logical to keep the code clean, just the bool value whenever we need to load the data table.

bool bIsDataTable =  UDataTable* Datas = LoadObject<UDataTable>(GetWorld(), TEXT("/Game/Data/MyDatatable"));
if(bIsDataTable)
{
//Logics
}

First thing first, there are no such word called “Datas”, Data is plural form of “Datum”.

To answer to your question is :
When you load object to a pointer you are assigning it an address. That means that pointer is filled. If you use it in if statement, if will act it like true. If its a null pointer it will be false. But its different than the bool.

So long story short you need to have something like this

UDataTable* Data = LoadObject<UDataTable>(GetWorld(), TEXT("/Game/Data/MyDatatable"));

if(Data)
{
   //Logics
}
2 Likes

Thank you sir for correcting me, I was thinking that if is actually assigning normal bool to the value out of the scene, but you cleared my doubt… thank you very much :slight_smile: