Daily Unreal Column #39 - Console Variables
Being a user of Unreal Engine and not using any of its console variables is almost impossible. Its very easy to create your own and here is how.
Creating your own console variable is very easy. Inside a source file where you wish to use a console variable, make a following definition:
static TAutoConsoleVariable<bool> CVarNameOfYourVariable(
TEXT("Category.Sub.Sub.Name"),
false,
TEXT("This is your help text")
);
Now, let's break down what is happening here.
TAutoConsoleVariable
- this is a variable type.<bool>
- this is template type of your console variable; major primitive types are allowed sobool
,int32
,float
anddouble
CVarNameOfYourVariable
- this is name of your variable; noticeCVar
prefix: while its completely optional, I like to put it just to ensure that reader is aware that its a console variableTEXT("Category.Sub.Sub.Name")
- this is how we are going to be referring to this variable in the consolefalse
- default value of the variableTEXT("This is your help text")
- help text that will be displayed next to the name of the variable in the consolename of the variable in the console
To update value of the console variable open the console by tapping tilda key and type Category.Sub.Sub.Name true
or Category.Sub.Sub.Name false
.
To access value of the variable type CVarNameOfYourVariable.GetValueOnGameThread()
.