Class CVar

A CVar is a special type of global variable that can have it's value changed during runtime or due to some specific configuration files loaded by the framework during startup.

To declare a CVar in C++ code, you can do the following:

Please note that the CVar is a global static variable.

The first parameter is the variable name. It is a unique identifier that is used to set it's value on the editor UI, a configuration file or during runtime by another system.

The second parameter is the default value. This value will be used by the system if no other replacement is given by the user either via the Editor UI, a configuration file or during runtime.

The third parameter is a description string. This string is used to explain to the user what the variable is, what it purpose is and what are the valid values that it can be set to.

A fourth and optional parameter is a number of flags. These flags can be used to customize the variable behaviour. For example, a variable can be made read-only by setting

The CVar system supports the following data types: float, bool, int64 or String. A number of operators and implicit conversion that make possible to use the stored value similarly to any other regular object. For example, to use a the CVar as boolean value, you can do the following:

The CVar system will automatically and implicitly convert any value set to it to a boolean value it will be evaluated on the if expression. For example, this variable could be set to true by setting it as: - true as a boolean; - 1 as an integer;

  • "true" as a string.

The same implicit conversion mechanism is available for all supported data types.

Each CVar is automatically registered with the global CVarManager during construction and automatically unregistered on destruction. Registering and unregistering is thread-safe, meaning that dynamically loaded libraries can register new CVars as static global variables.

Hierarchy

  • FrameworkObject
    • CVar

Constructors

  • Parameters

    • OptionalisInternalConstructor: boolean

    Returns CVar

Accessors

  • get boolValue(): boolean
  • Sets the value to bool value.

    Returns boolean

  • set boolValue(value): void
  • Parameters

    • value: boolean

    Returns void

  • get defaultBoolValue(): boolean
  • Gets the default bool value from the CVar.

    Returns boolean

  • get defaultFloatValue(): number
  • Gets the default float value from the CVar.

    Returns number

  • get defaultIntegerValue(): number
  • Gets the default int64 value from the CVar.

    Returns number

  • get defaultStringValue(): string
  • Gets the default String value from the CVar.

    Returns string

  • get description(): string
  • The variable description. Used to describe what the variable is used for to the user.

    Returns string

  • get floatValue(): number
  • Sets the value to float value.

    Returns number

  • set floatValue(value): void
  • Parameters

    • value: number

    Returns void

  • get integerValue(): number
  • Sets the value to int64 value.

    Returns number

  • set integerValue(value): void
  • Parameters

    • value: number

    Returns void

  • get name(): string
  • The variable name. Used to locate it within a configuration file or to be set by the user.

    Returns string

  • get stringValue(): string
  • Sets the value to String value.

    Returns string

  • set stringValue(value): void
  • Parameters

    • value: string

    Returns void

Methods

  • Resets the CVar to it's default value.

    Returns void

Events

onValueChange: Event<[], void>

An event triggered by the CVar whenever it's value changes.