Hi there,
I recently migrated from Unity Remote Settings to Unity Remote Config in order to avoid the config limit.
I only have the two initial environments (Release and Development), and to both of them I imported settings from my Remote Settings as per Unity’s own guide . Neither have Rules as I want this config to be available to all players.
I was able to Pull the config to Unity through the Remote Config window.
For some reason, however, I am unable to pull the data from Unity Config. The request is sent and I believe it returns successfully, but it’s as if none of my configs are present - when I try to get an int, for example, I always have 0 returned. From what I understand this is the behavior when a key cannot be found.
I wrote this class to manage interactions with Remote Config. This class is attached to an otherwise empty gameobject in the start scene:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using Unity.RemoteConfig;
using System;
public class RemoteConfigManager : MonoBehaviour
{
public static RemoteConfigManager RemoteConfig;
private void Awake()
{
if (RemoteConfig != null && RemoteConfig != this)
{
Destroy(this.gameObject);
return;
}
RemoteConfig = this;
DontDestroyOnLoad(this);
ConfigManager.FetchCompleted += ApplyRemoteSettings;
}
void ApplyRemoteSettings(ConfigResponse configResponse)
{
// Conditionally update settings, depending on the response's origin:
switch (configResponse.requestOrigin)
{
case ConfigOrigin.Default:
Debug.Log("No settings loaded this session; using default values.");
break;
case ConfigOrigin.Cached:
Debug.Log("No settings loaded this session; using cached values from a previous session.");
break;
case ConfigOrigin.Remote:
Debug.Log("New settings loaded this session; update values accordingly.");
break;
}
}
public int GetInt(string key, int default_value)
{
try
{
return ConfigManager.appConfig.GetInt(key);
}
catch
{
return default_value;
}
}
public float GetFloat(string key, float default_value)
{
try
{
return ConfigManager.appConfig.GetFloat(key);
}
catch
{
return default_value;
}
}
public string GetString(string key, string default_value)
{
try
{
return ConfigManager.appConfig.GetString(key);
}
catch
{
return default_value;
}
}
public bool GetBool(string key, bool default_value)
{
try
{
return ConfigManager.appConfig.GetBool(key);
}
catch
{
return default_value;
}
}
}
Other scripts throughout the game can reference the static variable RemoteConfig to get data when they need it:
private void Start()
{
if (globalFillMultiplier == -1f)
globalFillMultiplier = RemoteConfigManager.RemoteConfig.GetFloat("global_FillMultiplier", globalFillMultiplier_defaultValue);
}
I assume I am failing because I forgot something or misunderstood the documentation. Please let me know if you have any idea what might be wrong
Specs & Versions:
- Using Unity 2020.1.3f1
- Using the verified Remote Config package (1.0.9)
P.S.
On a different note, I want to never use cached Remote Config data. How can I disable it?
Thanks in advance!