UnigineEditor
Interface Overview
Assets Workflow
Settings and Preferences
Working With Projects
Adjusting Node Parameters
Setting Up Materials
Setting Up Properties
Lighting
Landscape Tool
Using Editor Tools for Specific Tasks
Extending Editor Functionality
Programming
Fundamentals
Setting Up Development Environment
Usage Examples
UnigineScript
C++
C#
UUSL (Unified UNIGINE Shader Language)
File Formats
Rebuilding the Engine Tools
GUI
Double Precision Coordinates
API
Containers
Common Functionality
Controls-Related Classes
Filesystem Functionality
GUI-Related Classes
Math Functionality
Node-Related Classes
Objects-Related Classes
Networking Functionality
Pathfinding-Related Classes
Physics-Related Classes
Plugins-Related Classes
IG Plugin
CIGIConnector Plugin
Rendering-Related Classes

Unigine::Config Class

Header: #include <UnigineConfig.h>

The Config class is used to read values (settings) from the XML configuration file (data/configs/default.config by default) and write them back to it.

Use the appropriate methods depending on the type of the target item. For example, to get the values of the following items, you should use the getInt() and getString() methods respectively:

Source code (XML)
...
<item name="show_fps" type="int">1</item>
<item name="system_script" type="string">unigine_project/unigine.usc</item>
...

Usage Example#

By using the Config class, you can save custom settings to the configuration file and then restore it when required. For example:

AppSystemLogic.h:

Source code (C++)
#include <UnigineLogic.h>
#include <UnigineConfig.h>
#include <UnigineConsole.h>

using namespace Unigine;

class AppSystemLogic : public Unigine::SystemLogic {
	
public:
	AppSystemLogic();
	virtual ~AppSystemLogic();
	
	virtual int init();
	
	virtual int update();
	virtual int render();
	
	virtual int shutdown();
	virtual int destroy();

private:

	Unigine::String player_avatar;
	int skip_cutscenes;
	int blood_enabled;
	int bulletshell_lifetime;
};

AppSystemLogic.cpp:

Source code (C++)
#include "AppSystemLogic.h"

int AppSystemLogic::init() {

	// read custom user-defined settings from the configuration file
	player_avatar = Config::getString("player_avatar", "usa_soldier1");
	skip_cutscenes = Config::getBool("skip_cutscenes", false);
	blood_enabled = Config::getBool("blood_enabled", false);
	bulletshell_lifetime = Config::getInt("bulletshell_lifetime", 100);

	return 1;
}

int AppSystemLogic::shutdown() {

	// automatically save the configuration file at shutdown
	Config::setAutosave(true);

	// write the custom settings to the configuration file
	Config::setString("player_avatar", player_avatar.get());
	Config::setBool("skip_cutscenes", skip_cutscenes);
	Config::setBool("blood_enabled", blood_enabled);
	Config::setInt("bulletshell_lifetime", bulletshell_lifetime);
	// save data to the custom configuration file, which is different from the default one
	Config::setPath("unigine_project/data/configs/my.config");
	Config::save();

	return 1;
}

See Also#

Config Class

Members


static void setBool ( const char * name, int value ) #

Sets a value of the given boolean setting. If the setting with this name already exists, its value is overwritten.

Arguments

  • const char * name - Name of the setting.
  • int value - Boolean value (0 or 1). 0 stands for false, 1 stands for true.

static int getBool ( const char * name ) #

Reads the value of the given boolean setting.

Arguments

  • const char * name - Name of the setting.

Return value

Boolean value (0 or 1) of the setting. 0 stands for false, 1 stands for true.

static int getBool ( const char * name, int value ) #

Reads the value of the given boolean setting. Returns the value specified as the second argument if the setting isn't found.

Arguments

  • const char * name - Name of the setting.
  • int value - Custom value to be returned if the setting isn't found.

Return value

Boolean value (0 or 1) of the setting. 0 stands for false, 1 stands for true.

static int isExist ( const char * name ) #

Checks if the setting with the given name exists.

Arguments

  • const char * name - Name of the setting.

Return value

1 if the setting exists; otherwise, 0.

static void setFloat ( const char * name, float value ) #

Sets a value of the given float setting. If the setting with this name already exists, its value is overwritten.

Arguments

  • const char * name - Name of the setting.
  • float value - Float value of the setting.

static float getFloat ( const char * name, float value ) #

Reads the value of the given float setting. Returns the value specified as the second argument if the setting isn't found.

Arguments

  • const char * name - Name of the setting.
  • float value - Custom value to be returned if the setting isn't found.

Return value

Float value of the setting.

static float getFloat ( const char * name ) #

Reads the value of the given float setting.

Arguments

  • const char * name - Name of the setting.

Return value

Float value of the setting.

static void setInt ( const char * name, int value ) #

Sets a value of the given integer setting. If the setting with this name already exists, its value is overwritten.

Arguments

  • const char * name - Name of the setting.
  • int value - Integer value of the setting.

static int getInt ( const char * name ) #

Reads the value of the given integer setting.

Arguments

  • const char * name - Name of the setting.

Return value

Integer value of the setting.

static int getInt ( const char * name, int value ) #

Reads the value of the given integer setting. Returns the value specified as the second argument if the setting isn't found.

Arguments

  • const char * name - Name of the setting.
  • int value - Custom value to be returned if the setting isn't found.

Return value

Integer value of the setting.

static void setString ( const char * name, const char * value ) #

Sets a value of the given string setting. If the setting with this name already exists, its value is overwritten.

Arguments

  • const char * name - Name of the setting.
  • const char * value - String value of the setting.

static const char * getString ( const char * name, const char * value ) #

Reads the value of the given string setting. Returns the value specified as the second argument if the setting isn't found.

Arguments

  • const char * name - Name of the setting.
  • const char * value - Custom value to be returned if the setting is found.

Return value

String value of the setting.

static const char * getString ( const char * name ) #

Reads the value of the given string setting.

Arguments

  • const char * name - Name of the setting.

Return value

String value of the setting.

static int load ( ) #

Loads config from the file. To change the path to the configuration file use the setPath() method.
Notice
To access the value via the Console, use the config_load console command.

Return value

true if the config is successfully loaded from the file; otherwise, false.

static void remove ( const char * name ) #

Removes the setting with the given name from the configuration file.

Arguments

  • const char * name - Name of the setting.

static int save ( ) #

Saves the current configuration to the file. To change the path to the configuration file use the setPath() method.
Notice
To access the value via the Console, use the config_save console command.

Return value

true if the current configuration is successfully saved to the file; otherwise, false.

static void setPath ( const char * path ) #

Sets a new path to the Engine config file (default: data/configs/default.config).
Notice
To access the value via the Console, use the config console command.

Arguments

  • const char * path - New path to the Engine configuration file to be set.

static const char * getPath ( ) const#

Returns the current path to the Engine config file (default: data/configs/default.config).
Notice
To access the value via the Console, use the config console command.

Return value

Current path to the Engine configuration file.

static void setAutosave ( bool autosave ) #

Sets a value indicating if current Engine configuration settings are automatically saved to the corresponding config file on loading, closing, and saving the world, as well as on the Engine shutdown.
Notice
To access the value via the Console, use the config_autosave console command.

Arguments

  • bool autosave - true to enable automatic saving of current Engine configuration settings; false — to disable it.

static bool isAutosave ( ) const#

Returns a value indicating if current Engine configuration settings are automatically saved to the corresponding config file on loading, closing, and saving the world, as well as on the Engine shutdown.
Notice
To access the value via the Console, use the config_autosave console command.

Return value

true if automatic saving of current Engine configuration settings is enabled; otherwise, 0.
Last update: 2020-07-28