---
name: "loadConfig"
type: command
status: ok
groups: ["Config"]
arma3_since: "2.10"
locality: {"argument": null, "effect": null, "server_exec": false}
source: https://community.bistudio.com/wiki/loadConfig
revid: 341399
updated: 2023-05-25T14:02:22Z
---

# loadConfig

*Command · Config · Arma 3 v2.10*

## Description

Loads the given file as a [Config](../topics/Config.md), allowing easy processing of the config file contents using commands such as [configClasses](../commands/configClasses.md), [configProperties](../commands/configProperties.md), [>>](../commands/config_greater_greater_name.md), etc. It can load .rvmat, .bisurf, .cpp, .bin, .sqm, and [description.ext](../topics/Description.ext.md) files (both binarized and unbinarized configs are supported).

> [!IMPORTANT]
> - Config loading can be very slow; the config should only be loaded once and cached, e.g in a [HashMap](../topics/HashMap.md) of `File Path → Config` pairs (see [#Example 3](../commands/loadConfig.md#example-3)).
> - It is advised to store the generated config in a variable, otherwise it will get destroyed if it is not being referenced directly (see [#Example 2](../commands/loadConfig.md#example-2)).

## Syntax

```sqf
loadConfig path
```

**Parameters:**

- `path`: [String](../topics/String.md) - path to the file, which should be in a valid config format.

**Returns:** [Config](../topics/Config.md) - loaded config. Returns [configNull](../commands/configNull.md) if the file doesn't exist.

## Examples

### Example 1

```sqf
private _cfg = loadConfig "a3\data_f\default_super.rvmat"; // note: very slow! ~0.1200 ms on tested system
getText (_cfg >> "Stage2" >> "uvSource");
```

### Example 2

```sqf
// INCORRECT - the config is destroyed after the first operator >> accesses it
getNumber (loadConfig "mission.sqm" >> "ScenarioData" >> "respawnDelay");

// CORRECT - the config is destroyed only when the variable _cfg is destroyed
_cfg = loadConfig "mission.sqm";
getNumber (_cfg >> "ScenarioData" >> "respawnDelay");
```

### Example 3

```sqf
// using a hashmap to cache loaded configs, since loading configs is very slow and should be done once.
private _fnc_loadConfig = {
    params ["_path"];
    // initialize cache if not initialized yet
    if (isNil "TAG_configCache") then
    {
        TAG_configCache = createHashMap;
    };
    private _cfg = TAG_configCache getOrDefault [_path, configNull];
    // if path doesn't exist in the cache or cfg is null, load the config
    if (isNull _cfg) then
    {
        _cfg = loadConfig _path;
        TAG_configCache set [_path, _cfg];
    };
    _cfg;
};
// the first call will be slow (~0.1200 ms), but subsequent calls are fast (~0.0050 ms)
["a3\data_f\default_super.rvmat"] call _fnc_loadConfig;
```

### Example 4

```sqf
// converting a config into hashmap
private _fnc_convertClass = {
    params ["_cfgClass"];

    private _result = createHashMap;
    private _props = configProperties [_cfgClass, "true", true];
    // note: Hashmaps are case-sensitive so configName cases have to be consistent (e.g. all lowercase)
    {
        if (isNumber _x)    then { _result set [toLowerANSI configName _x, getNumber _x];    continue; };
        if (isText _x)        then { _result set [toLowerANSI configName _x, getText _x];        continue; };
        if (isArray _x)        then { _result set [toLowerANSI configName _x, getArray _x];    continue; };
    } forEach _props;

    private _classes = "true" configClasses _cfgClass;
    {
        _result set [toLowerANSI configName _x, _x call _fnc_convertClass];
    } forEach _classes;

    _result;
};

private _cfg = loadConfig "mission.sqm";
private _cfgMap = _cfg call _fnc_convertClass;

// the following expression is similar to getNumber(_cfg >> "EditorData" >> "moveGridStep")
// note that all strings are lowercase (which is how they were stored in hashmap)
_cfgMap get "editordata" get "movegridstep";
```

## See also

[loadFile](../commands/loadFile.md) · [config greater greater name](../commands/config_greater_greater_name.md) · [configFile](../commands/configFile.md) · [configClasses](../commands/configClasses.md) · [isText](../commands/isText.md) · [isNumber](../commands/isNumber.md) · [isArray](../commands/isArray.md) · [isClass](../commands/isClass.md) · [configName](../commands/configName.md) · [getText](../commands/getText.md) · [getNumber](../commands/getNumber.md) · [getArray](../commands/getArray.md)

## Community notes

**Dedmen** — 2022-03-22

When trying to load a terrain surface name, like you get from Ammo Eventhandlers when you hit the terrain, you can simply use

```sqf
private _config = configFile >> "CfgSurfaces" >> _surfaceName;
```

You can recognize surface names by them not having any \ path separators in them, they usually start with gdt, for example "gdtvrsurface01".

<sub>Source: [BI Community Wiki — loadConfig](https://community.bistudio.com/wiki/loadConfig) (revision 341399).</sub>
