GConfig can not be recognized/ can not be defined?

hi guys, I try to modify the ini file in my game project access using BlueprintLibrary class, but my VS can not find out GConfig as it invoked. my code is on the below:



//MyBlueprintFunctionLibrary.h

#include "Kismet/BlueprintFunctionLibrary.h"
#include "MyBlueprintFunctionLibrary.generated.h"

/**
*
*/
UCLASS()
class CPP_API UMyBlueprintFunctionLibrary : public UBlueprintFunctionLibrary
{
GENERATED_BODY()

public:
UFUNCTION(BlueprintCallable, Category = "FileConfig")
static float ReadConfig();

UFUNCTION(BlueprintCallable, Category = "FileConfig")
static int ReadConfigInt(FString key, int iDefaultValue);

};




//MyBlueprintFunctionLibrary.cpp



float UMyBlueprintFunctionLibrary::ReadConfig() {

float ValueReceived = 0.f;

return ValueReceived;
}

int UMyBlueprintFunctionLibrary::ReadConfigInt(FString key, int iDefaultValue) {
{
if (!GConfig) return 0;

int fValueReceived = 0;
FString VictorySection = "DefaultSetting";

if (GConfig->GetInt(
*VictorySection,
*key,
fValueReceived,
GGameIni
))
{
return fValueReceived;
}

}

the compile error message is on “if (GConfig->GetInt())” , says pointer to incomplete class type is not allowed, can anyone tell me if I missed any head file or how to invoke GConfig?

It’s complaining because it doesn’t know what GConfig is. That’s what “pointer to incomplete class type is not allowed” means.

GConfig seems to be declared in CoreGlobals.h - so you need to include that header in your CPP file.

I include the CoreGlobals.h file this time, but it still says:

Error (active) E0393 pointer to incomplete class type is not allowed

is that because my compiler didnt figure out the head file? my Cpp code is:

include “MyBlueprintFunctionLibrary.h”

include “CoreGlobals.h”

float UMyBlueprintFunctionLibrary::ReadConfig() {

float ValueReceived = 0.f;

return ValueReceived;

}

int UMyBlueprintFunctionLibrary::ReadConfigInt(FString key, int iDefaultValue) {
{
if (!GConfig) return 0;

    int fValueReceived = 0;
    FString VictorySection = "DefaultSetting";

    if (GConfig->GetInt(
        *VictorySection,
        *key,
        fValueReceived,
        GGameIni
    ))
    {
        return fValueReceived;
    }

}

Not sure if you’re still interested in the solution, but I encountered the same issue you had, with the “pointer to incomplete class type is not allowed”.

Reading up on the docs for GConfig on Unreal docs (GConfig | Unreal Engine Documentation), it indictes that it’s of type FConfigCacheIni.
Going into the docs for FConfigCacheIni reveals that the include for it is: #include “Misc/ConfigCacheIni.h”

Indeed, if you go into the Core module doc link for it (Core | Unreal Engine Documentation) and do a find on “GConfig” in it, you’ll find that it’s a variable of the Core module.

After using #include “Misc/ConfigCacheIni.h” (instead of CoreGlobals.h), it seems to compile fine for me now.

Hopefully this should help anyone else that also comes across this issue (assuming further edits/refactoring aren’t made by Epic that impacts this).

2 Likes