I’m having a problem where it seems static variables initialized in the top of the .cpp file are not initialized properly.
ItemFunctionLibrary.h:
UCLASS(BlueprintType)
class MYPROJECT_API UItemFunctionLibrary : public UBlueprintFunctionLibrary
{
GENERATED_BODY()
private:
static bool s_initialized;
public:
UFUNCTION(BlueprintCallable, Category = "ItemFunctionLibrary") static bool LoadItem(const FName itemID, UItem*& itemOut);
static void Initialize();
}
ItemFunctionLibrary.cpp
bool UItemFunctionLibrary::s_initialized = false;
bool UItemFunctionLibrary::LoadItem(const FName itemID, UItem*& itemOut)
{
if(s_initialized == false) // s_initialized is always TRUE
{
Initialize(); // never hit
}
// other stuff
}
void UItemFunctionLibrary::Initialize() // entire function is never called
{
s_initialized = true;
// other stuff
}
I’m not sure what I’m doing wrong. I’ve used this version of initialization in other C++ programs before, but it doesn’t work in this version.