Setting and Loading configuration

Dear Unity community,

I have a requirement which I was not able to resolve by googeling.

I have a couple scripts on gameobjects that define settings for my game, e.g. shoult it connect to Steam or not, am I in developer cheat mode or not, do I use VR or not, etc. I’m doing the setup currently in Editor.

I would like to create different configurations for my game and set them via script, so I can link the setting to a menu entry or button and just set it before building the game.

However, I fail to understand how I can modify editor values of gameobjects.

Does anyone have an idea how this can be done?

Thank you!

Is this something you are looking for ?

You could have a Settings ScriptableObject, and a SettingsManager that contains the current settings. Every different configuration would be a new asset, so a SteamSettings etc.

Hmm, I had thought about that as well. I was hoping I could hard-Code settings somehow - but this might do as well. Thank you!

Why would you want that?

You could always just have some Struct in your code and assign these to a Current property.

You could add a simple button to the inspector which can apply those ScriptableObject values in the editor.

Make an Editor script for your main script, then use DrawDefaultInspector to draw it as normal, then add a button underneath to apply all the settings, then you can build your game.

using UnityEngine;
using UnityEditor;
using System.Collections;

[CustomEditor(typeof(MyScriptName))]
public class MyScriptNameEditor : Editor {

    public override void OnInspectorGUI()
    {
        DrawDefaultInspector();

        if (GUILayout.Button("Apply", GUILayout.Height(20f)))
        {
            ...
        }
    }

}

Or just use a menu drop down to apply different settings.

1 Like