ConfigManager - Manage configuration in Unity centrally

May I ask you something? How do you configure your game? For once, we're not talking about user settings, but about the configuration you make to the game yourself. How fast the player moves, how much damage enemies do, how many gold coins an armor costs. Do you set all this individually for each MonoBehaviour? It would be great if you can store all this in one place. This is possible with the ConfigManager.

One configuration to rule them all

The ConfigManager works like this: You have a central JSON file where you can store all configurable values. Currently supported are: float, string, int, bool, Vector2, Vector3, Vector4, Quartenion, Color and Color32. The JSON file is then loaded by the ConfigManager at game start and the values from it are available to you. You can then access the ConfigManager in any MonoBehaviour and load the values that the script needs to operate.

The file may then look like this, for example:

  "playerSpeed": 100f,
  "enemyDamage": 25f,
  "priceArmor": 500

You can then reference this file in the ConfigManager (via the Unity Editor). The values from it are then loaded and available to you. You can then access it like this, for example:

public class Player : MonoBehaviour
    private float speed;

    private void Awake()
        speed = ConfigManager.service?.Get("playerSpeed", 0f);

Basically, the ConfigManager works just like any other StorageManager, because under the hood it uses the RuntimeStorageManager to hold the data.

A small drawback is, however, that no nesting of data is possible. That is, a simple key-value object is supported. Therefore it is best to use prefixes to keep the configuration clear.

If you want to use several configuration files for different purposes, you can also simply use the ConfigService directly and load a different file each time. You can decide here completely according to your own preference and the complexity of the project.

Your Feedback is important!

What do you think of the services presented here? Is there anything missing or does something not work as expected? As always, I'm happy to listen to your feedback. Let me know what you think about this module. You can use the comment section below the article for this. You can also find other ways to contact me here. If you found a bug or want an enhancement, please create an issue in the GitHub repository. Further documentation can be found in the README of the corresponding module.

There are no comments yet.