Can I set default config in case of first game run without internet connection?
I think the most easy way to solve this situation is load config from resources and manually set it, or give possibility to set default config from editor but there is no functional to do this (or i couldn’t find it).
So if my config contains (for example) more then 1000 values and there is no internet connection - I need to set manually each field with default value in code? And for each default value change i need to manage this values?
Even if I already have all default values predefined in my editor config?
It sounds like hell.
All Apple Arcade games should have an opportunity to be ran without internet connection, so for Arcade games this config is useless?
For now I’m using my own config file downloaded from sftp, but I’m interested to upgrade to Remote Config package.
I’ll try to explain more detailed: when user first runs an application without internet connection - config with default values (zeroes and empty strings) will be generated without any rules and key value pairs in it.
And now I’m as developer who wants to make his partially offline game should make a couple of things to make this work:
download remote config in editor and get scriptable object with already preset values, put it in my resources folder.
write my own parser for this config (keyValuePairs, rules) to copy values from my resources pre-downloaded config to default generated config
safely start the game
Method you have offered may help me to write my own parser, but in my opinion this is basic functionality that should already be included in this package.
Thank you for your suggestion. You could essentially do the same with a single INCLUDE file for your default values, and edit them in one place. Default values would not be expected to change often, and typically include values other than 0’s and 1’s. I am also checking with the team here.
I have the same problem. I created a config and wrote the default values there, which I plan to change remotely. Then I built an app that included this config with default values. I expect that if there is no Internet, I will get my default value, but I get “0”
using System.Collections;
using System.Collections.Generic;
using Unity.RemoteConfig;
using UnityEngine;
public class RemoteConfig : MonoBehaviour
{
public static float levelBalance = 0.1f; // 0.1 value for test
public struct UserAttributes
{
// Optionally declare variables for any custom user attributes:
public int level;
}
public struct AppAttributes
{
// Optionally declare variables for any custom app attributes:
public string appVersion;
}
// Retrieve and apply the current key-value pairs from the service on Awake:
void Awake()
{
// Add a listener to apply settings when successfully retrieved:
ConfigManager.FetchCompleted += ApplyRemoteSettings;
// Set the user’s unique ID:
//ConfigManager.SetCustomUserID("some-user-id");
// Set the environment ID:
ConfigManager.SetEnvironmentID("91dae037-7973-4643-b9c4-f3f15b972f2e");
// get default value
levelBalance = ConfigManager.appConfig.GetFloat("Level1Balance"); // expect 3.17, but get 0
}
void Start()
{
FetchConfig();
}
private void FetchConfig()
{
var userAttributes = new UserAttributes();
var appAttributes = new AppAttributes();
userAttributes.level = MM.Inventory.GetInt(MM.Inventory.LEVEL_ID);
appAttributes.appVersion = Application.version;
// Fetch configuration setting from the remote service:
ConfigManager.FetchConfigs<UserAttributes, AppAttributes>(userAttributes, appAttributes);
}
void ApplyRemoteSettings(ConfigResponse configResponse)
{
// Conditionally update settings, depending on the response's origin:
switch (configResponse.requestOrigin)
{
case ConfigOrigin.Default:
Debug.Log($"RemoteConfig: No settings loaded this session; using default values.");
break;
case ConfigOrigin.Cached:
Debug.Log($"RemoteConfig: No settings loaded this session; using cached values from a previous session.");
break;
case ConfigOrigin.Remote:
Debug.Log($"RemoteConfig: New settings loaded this session; update values accordingly.");
levelBalance = ConfigManager.appConfig.GetFloat("Level1Balance"); // I get 0 again
break;
}
}
}
}
if the Internet is available I get 3.17. And after the first Internet connection I get 3.17 without Internet.
UPD: I get: configResponse.status == ConfigRequestStatus.Failed and configResponse.requestOrigin == ConfigOrigin.Remote.
But I expect: configResponse.status == ConfigRequestStatus.Success and configResponse.requestOrigin == ConfigOrigin.Default
Please try moving this line from Awake to the last line in FetchConfig, Awake is fired before Start and you haven’t yet initialized RC and a null is likely treated as 0.
levelBalance = ConfigManager.appConfig.GetFloat(“Level1Balance”); // expect 3.17, but get 0
Thank you, this is really my mistake, but it didn’t help. I still get 0 and ConfigRequestStatus.Failed. Also file RemoteConfig.json in my persistentDataPath folder (MacOS) is not created without the Internet connection.
And then what? I still expect to get the value from the local config (3.17), not duplicate it in the code. Is this a confirmed bug or a problem only on my project?
You can set the default value to anything you want. The second parameter is the default value if there is no Internet connection. If you have connected at least once in the past, it will use the last retrieved (and cached) value. If the user has never connected and this is their first request and there is no Internet, it will use the default value.