Changing Manager fields at runtime

Any Manager field can be modified at runtime through script - just right-click a field's label to get an API reference to it.

As an example, we'll change the Settings Manager's Movement method field, which is found in the "Interface settings" panel:

Right-clicking this field's label gives us a Copy script variable option:

Doing so copies an API reference to this field into the text buffer, which can be pasted into a custom script:

AC.KickStarter.settingsManager.movementMethod

Lets add the ability to switch the Movement method to either Point And Click or Direct through ActionList. To do this, we'll first need to create a new C# file from the Project window, and use the copied reference inside functions that set its value.

Here, we've created a C# script named SetMovementMethod, and given it two functions: SwitchToPointAndClick and SwitchToDirect. These functions are public so that they can be called externally:

using UnityEngine;

public class SetMovementMethod : MonoBehaviour
{

    public void SwitchToPointAndClick ()
    {
        AC.KickStarter.settingsManager.movementMethod = AC.MovementMethod.PointAndClick;
    }

    public void SwitchToDirect ()
    {
        AC.KickStarter.settingsManager.movementMethod = AC.MovementMethod.Direct;
    }

}

Attach this to a new GameObject in the scene, and make it a prefab by dragging it in the project window. Rename the prefab to something like MovementSetter, and delete the original GameObject from the scene.

We now just need to have a means of triggering these functions at the intended time. This can be done in ActionLists using the Object: Call event Action.

In this Action, click the + icon to create a new event. Then, set the Runtime object - be sure to set this to the prefab, MovementSetter, and not the original script file. We can then use the drop-down menu to choose which function to call:

When this Action runs, it will then call the script's SwitchToDirect function - which will update the game's Movement method.

One more thing to be aware of, however: changes made to Manager field values will survive exiting Play mode - so you'll need to make sure that these fields set correctly when your game begins. To do this, use another such Action in your game's ActionList on start game asset, which can be assigned at the top of the Settings Manager.