Create/Register a console variable

If you want to create a console variable use static TAutoConsoleVariable in a CPP file of your choice. Supported and recommended types are FString, float, and int32.

static TAutoConsoleVariable CVarMyDebugFlag(TEXT("MyDebugFlag"),
  0, 
  TEXT("Well this is just a test debug flag.\n") 
  TEXT("<=0: off \n") 
  TEXT(">=1: enable debug something\n"),
  ECVF_Cheat);
C++

If you want to create a console variable inside a method use IConsoleManager::Get().RegisterConsoleVariable. Supported types are FStringfloat, and int32.

IConsoleManager::Get().RegisterConsoleVariable(
    TEXT("MyDebugFlag"), 
    0, 
    TEXT("Well this is just a test debug flag.\n") 
    TEXT("<=0: off \n") TEXT(">=1: enable debug something\n"),
    ECVF_Cheat);
);
C++

Getting State of a console variable

To get the state of a variable, just use your registered variable name.

// only needed if you are not in the same cpp file 
extern TAutoConsoleVariable CVarMyDebugFlag; 

// get the value on the game thread 
int32 MyVar = CVarMyDebugFlag.GetValueOnGameThread();
C++

For more informations regarding console variables, please read the official docs of Epic ConsoleManager