Config File

Overview

The base RIDE library uses a config file to store configuration information needed to run certain RIDE systems and services.

Page Contents

Config File

The base RIDE library uses a config file to store configuration information needed to run certain RIDE systems and services.

It stores this as user-specific information so that it can be changed if desired.

For example, users/developers may be given a specific access key to download assets.  This key will be stored in the config file.

Config File Version

The config file contains a version.  If the version has been updated due to upgrading RIDE, then the config service will detect the config version mismatch.

The user/developer needs to decide what action to take in order to upgrade the config file.

The config service will not automatically upgrade the config file.  This is by design, so that the user/developer does not lose any custom data that may be entered.  For example, if the user has a specific terrain access key, the key could be lost if the system automatically upgraded the config file.

Before upgrading the config file, the user/developer should store a copy of the config file, keeping any custom changes they may have.

Then, the user/developer can choose to reset the config file to its defaults, which will upgrade it to the latest config file version.

Reset to defaults via RIDE repository

If you are working out of the RIDE repository, you can reset the config file via the Level Select Options menu.  The Options menu will detect a version mismatch, and provide the user/developer with the ability to reset the config file to its defaults. Additionally, the Config tab in the debug menu contains this functionality.

 

Reset to defaults via Project Specific repository

If you are working out of a project specific repository, you can provide the same functionality as the Level Select Menu (detecting version mismatch and providing the user with a choice to upgrade the config file).

If you know that you will always want to reset to defaults when the version changes, you can simply detect the mismatch at startup and automatically upgrade the config without prompting the user.  Just be aware of any consequences this may have.

If you would like to do this, add the following to your initialization code:

RideConfigService configService = Globals.api.serviceSystem.GetService<RideConfigService>();
if (!configService.IsCorrectVersion())
{
    configService.Reset();
    configService.Save();
} 

Config File Location

ref: https://docs.unity3d.com/ScriptReference/Application-persistentDataPath.html

User Name is the user that is logged in.

Company Name and Product Name is found in Unity Editor, inside Player Settings.

The config file can be located at the following paths, depending on the platform being used:

Windows

c:\Users\AppData\LocalLow\config\ride.json

MacOS

~/Library/Application Support/Company Name/Product Name/config/ride.json

iOS

/var/mobile/Containers/Data/Application/Documents/config/ride.json

Android

/storage/emulated/0/Android/data/files/config/ride.json

Application Specific Config

The RIDE config file is intended for RIDE API specific uses.  If your project needs to store configuration information, it is recommended to use your own config file.  RIDE provides an easy way to do this.  Follow this template to add your own config file:

MyProjectConfig.cs

using System;
 
namespace MyProject
{
    [Serializable]
    public struct MyProjectConfig
    {
        public Version version;
        public string ConfigSetting1;
        public bool UseSetting2;
 
 
        public static readonly MyProjectConfig Default = new MyProjectConfig
        {
            version = new System.Version("1.0.0.0"),
            ConfigSetting1 = "MySetting1",
            UseSetting2 = false,
        };
    }
} 

MyProjectConfigService.cs

using Ride;
using Ride.Services;
 
namespace MyProject
{
    public class MyProjectConfigService : ConfigurationService<MyProjectConfig>
    {
        const string FileName = "MyProject.json";
 
 
        public string path { get; private set; }  // initialized in ctor since it uses persistantDataPath
 
 
        public MyProjectConfigService()
        {
            path = string.Format("{0}/config/{1}", RideUtils.ApplicationPersistentDataPath(), FileName);
            Load();
        }
 
        public override MyProjectConfig Load()
        {
            m_config = MyProjectConfig.Default;
 
            if (System.IO.File.Exists(path))
            {
                string json = System.IO.File.ReadAllText(path);
                try
                {
                    m_config = RideUtils.JsonDeserialize<MyProjectConfig>(json);
                }
                catch (Newtonsoft.Json.JsonReaderException e)
                {
                    UnityEngine.Debug.LogWarningFormat("RideConfigService.Load() - error reading config file.  Is it out of date?  Exception: {0}", e);
                    m_config = MyProjectConfig.Default;
                }
            }
            else
            {
                Save();
            }
 
            return m_config;
        }
 
 
        public override void Save()
        {
            // make sure dest folder exists
            System.IO.Directory.CreateDirectory(System.IO.Path.GetDirectoryName(path));
 
            string json = RideUtils.JsonSerialize(m_config);
            System.IO.File.WriteAllText(path, json);
        }
 
 
        public MyProjectConfig Reset()
        {
            m_config = MyProjectConfig.Default;
            return m_config;
        }
 
 
        public bool IsCorrectVersion()
        {
            /// If this returns true, the config file has the incorrect version.
            /// You should call Reset(), then Save().
            /// However, you should give users/developers the opportunity to save the existing config file first
            /// so that any custom info is not lost.
            /// The intent of this function is to give projects this opportunity, instead of automatically resetting to defaults.
 
            return m_config.version == MyProjectConfig.Default.version;
        }
    }
} 

In any file that initializes your project, add the following line:

Globals.api.serviceSystem.AddService(new MyProject.MyProjectConfigService());