Updating the game settings dynamically with Remote Settings

July 27, 2019


Almost all games that are developed in Unity uses some configuration values for the game to run. These configurations may define the difficulty of the game, the transform properties of the game object or other such properties.
In this application, we will be using remote configurations to dynamically update the values for some game objects without the requirement of rebuilding or even re-installing the game on devices.

Enabling the Analytics Service

Unity’s Remote Settings is a feature available with the Unity’s Analytics service, so make sure that you have Unity Analytics enabled for your project. To enable Unity Analytics, click the cloud button near the inspector and switch on the Toggle for Unity Analytics.


Setting up the Project

To get started with the Project, I have simply created a 2D sprite which has a Rotator script attached to it.
using UnityEngine;
public class Rotator : MonoBehaviour { 
    public float Speed = 100f;     void Update() 
    { 
        transform.Rotate(0f, 0f, speed * Time.deltaTime);
    } 
}


The Rotator script has a property in the inspector named “Speed” for which we have set the value as 20. But imagine if the game is deployed and there are users using the app, and we decide to change this value from 20 to 90. Here comes the role of remote settings where we can update the Rotate Speed dynamically with a few clicks that too without uploading a different release for the app.

Creating the Remote Settings key-value pairs

Go to the  and open the project you created. Make sure that you are signed in on the Unity Editor on your machine. Navigate to Remote Settings option under Optimization in the navigation bar.

With Remote Settings selected, change the dropdown value to Development and create a new “Add New Key-Value” to create a new key named Speed of int type with value 25.


After creating the key-value pair, click on Sync button to sync values across Remote and Unity Editor.

The Unity Analytics Remote Settings unitypackage

To access these remote settings in our Unity Project, we need to import the  unitypackage.

Configuring Remote Settings

After importing the above unitypackage, click on Window -> Unity Analytics -> Remote Settings. This will open a window like this.


Now click on Look up the key text and it will redirect to the Unity Analytics Dashboard. Or simply navigate to Analytics Settings under Settings to find your private key.


Update the value for your private key and click on Next to get a screen like this.


Now you are all set up to use remote values in your project.

Updating the Rotator.cs script

Update the content of the Rotator script to have the following code:
using UnityEngine;

public class Rotator : MonoBehaviour
{
    public float Speed = 100f;

    private void Start()
    {
        Speed = RemoteSettings.GetInt("Speed");
    }

    void Update()
    {
        transform.Rotate(0f, 0f, Speed * Time.deltaTime);
    }
}
Observe the Start() where we are getting the value from unity remote server and sets these values dynamically.
On running, the value will be auto-updated to the value 25 that we have set on Analytics Dashboard.


Updating the Remote Values

To dynamically update the remote values, go to Analytics Dashboard and update the value of Speed variable to 90 and click on the Sync button.
Click on the Play button in the Editor and you will see the value is updated to 90.

You Might Also Like

0 comments

Follow by Email