Provides access to your remote settings.
At the start of a new session of your application, Unity makes a network request for the latest remote settings configuration from the Analytics Service. Unity requests the Release configuration when running regular, non-development builds of your application, and requests the Development configuration when running development builds. Play mode in the Unity Editor counts as a development build.
Note: For Unity to request the Development configuration, you must build the application with Unity version 5.6.0p4+, 5.6.1p1+, 2017.1+, or Unity 5.5.3p4+, and tick the Development Build checkbox on the Build Settings window. If you build the game with an older version of Unity, Unity always requests the Release configuration.
The RemoteSettings
object dispatches a BeforeFetchFromServer:: event before it makes the network request for settings.
The Remote Settings
object then dispatches an Updated event if a configuration file is available. Note that if the network request fails and a remote configuration file is not available, the RemoteSettings
object checks whether a local, cached configuration file is present. If so, it uses these cached values and still dispatches Updated. Updated is only not dispatched when the remote request fails and no cached version is present.
Whether or not the remote request succeeds, the RemoteSettings
object dispatches the Completed event. The parameters passed to the Completed
event provide the HTTP response code and whether a remote configuration file was received.
When the RemoteSettings
object receives a remote configuration it caches the file for use when the current computer or device is offline. However, if your game instance has not saved the settings yet (such as when a player has no network connection the first time they run your game), then the RemoteSettings object does not dispatch an Updated event, and so does not update your game variables. Requesting the Remote Settings configuration over the network is an asynchronous process that might not complete before your initial Scene has finished loading, or might not complete successfully at all, so you should always initialize your game variables to reasonable defaults.
Note: The web service from which Unity downloads the Remote Settings configuration is read-only, but is not secured. This means that the configuration could be read by third-parties. You should not put sensitive or secret information into your Remote Settings. Similarly, the saved settings file could be read and modified by end-users (although any modifications are overwritten the next time a session starts with an available Internet connection).
Create remote settings as key-value pairs on your Analytics dashboard.
You can only store basic types in the Remote Settings (int, float,
string and boolean).
See Also: Remote Settings (Manual).
using UnityEngine;
public class HandleRemoteSettings : MonoBehaviour { private void Start() { // Add this class's updated settings handler to the RemoteSettings.Updated event. RemoteSettings.Updated += RemoteSettingsUpdated; }
private static void RemoteSettingsUpdated() { Debug.Log("***** GOT NEW REMOTE SETTINGS ******"); Debug.Log(RemoteSettings.GetInt("testInt")); Debug.Log(RemoteSettings.GetString("testString")); Debug.Log(RemoteSettings.GetFloat("testFloat")); Debug.Log(RemoteSettings.GetBool("testBool")); Debug.Log(RemoteSettings.GetBool("testFakeKey")); Debug.Log(RemoteSettings.GetBool("testFakeKey", true)); Debug.Log(RemoteSettings.HasKey("qqq")); Debug.Log(RemoteSettings.HasKey("testInt")); Debug.Log(RemoteSettings.GetBool("unity.heatmaps")); } }
ForceUpdate | Forces the game to download the newest settings from the server and update its values. |
GetBool | Gets the value corresponding to remote setting identified by key, if it exists. |
GetCount | Gets the number of keys in the remote settings configuration. |
GetFloat | Gets the value corresponding to remote setting identified by key, if it exists. |
GetInt | Gets the value corresponding to remote setting identified by key, if it exists. |
GetKeys | Gets an array containing all the keys in the remote settings configuration. |
GetLong | Gets the value corresponding to remote setting identified by key, if it exists. |
GetString | Gets the value corresponding to remote setting identified by key, if it exists. |
HasKey | Reports whether the specified key exists in the remote settings configuration. |
WasLastUpdatedFromServer | Reports whether or not the settings available from the RemoteSettings object were received from the Analytics Service during the current session. |
BeforeFetchFromServer | Dispatched before the RemoteSettings object makes the network request for the latest settings. |
Completed | Dispatched when the network request made by the RemoteSettings object to fetch the remote configuration file is complete. |
Updated | Dispatched when a remote settings configuration is fetched and successfully parsed from the server or from local cache. |
UpdatedEventHandler | Defines the delegate signature for handling RemoteSettings.Updated events. |
Did you find this page useful? Please give it a rating: