Hi! Everywhere I look, global singleton looks like this:
It works fine, but here I thought, why not to do:
Which should, in theory, save some extra checks and casting time. Is there any catch? Like, maybe static variable declared outside the score, will actually be kept even after game stops playing in editor? But from what I think, it would become nullptr too
Code:
UDataTableHolder* UDataTableHolder::Get() { UDataTableHolder* DataInstance = Cast<UDataTableHolder>(GEngine->GameSingleton); if (!DataInstance) return NULL; if (!DataInstance->IsValidLowLevel()) return NULL; return DataInstance; }
Code:
static UDataTableHolder* DataInstance; void UDataTableHolder::Get() { if(DataInstance == nullptr) { DataInstance = Cast<UDataTableHolder>(GEngine->GameSingleton); if (!DataInstance) return NULL; if (!DataInstance->IsValidLowLevel()) return NULL; } return DataInstance; }
Comment