Search Unity

Remote Settings

Discussion in 'Unity Analytics' started by laurentlavigne, Jun 3, 2017.

  1. laurentlavigne

    laurentlavigne

    Joined:
    Aug 16, 2012
    Posts:
    6,365
    Remote settings looks very interesting. How does Remote Settings Component with scriptable objects? That's what I use to store enemy stats and other game settings.
     
  2. CharlesWard

    CharlesWard

    Unity Technologies

    Joined:
    Apr 19, 2017
    Posts:
    23
    Using ScriptableObjects directly with the component isn't currently supported. You could create a MonoBehaviour with properties that set your ScriptableObject fields (as described here: https://docs.unity3d.com/Manual/UnityAnalyticsRemoteSettingsComponent.html).

    Or, it might be easier to add a function to handle the RemoteSettings. Updated event to your scriptable objects:


    Code (CSharp):
    1.     using UnityEngine;
    2.  
    3.     public class ScriptableThing : ScriptableObject {
    4.  
    5.         public float DefaultSpawnRateFactor = 1.0f;
    6.         public float DefaultEnemySpeedFactor = 1.0f;
    7.         public float DefaultEnemyStrengthFactor = 1.0f;
    8.  
    9.         public static float SpawnRateFactor{ get; private set; }
    10.         public static float EnemySpeedFactor{ get; private set; }
    11.         public static float EnemyStrengthFactor{ get; private set; }
    12.  
    13.         void Awake () {
    14.             SpawnRateFactor = DefaultSpawnRateFactor;
    15.             EnemySpeedFactor = DefaultEnemySpeedFactor;
    16.             EnemyStrengthFactor = DefaultEnemyStrengthFactor;
    17.  
    18.             RemoteSettings.Updated +=
    19.                 new RemoteSettings.UpdatedEventHandler(HandleRemoteUpdate);
    20.         }
    21.  
    22.         private void HandleRemoteUpdate(){
    23.             SpawnRateFactor
    24.             = RemoteSettings.GetFloat ("SpawnRateFactor", DefaultSpawnRateFactor);
    25.             EnemySpeedFactor
    26.             = RemoteSettings.GetFloat ("EnemySpeedFactor", DefaultEnemySpeedFactor);
    27.             EnemyStrengthFactor
    28.             = RemoteSettings.GetFloat ("EnemyStrengthFactor", DefaultEnemyStrengthFactor);
    29.  
    30.             Debug.Log("Update settings");
    31.         }
    32.     }

    This is essentially the same technique described here, but for ScriptableObjects: https://docs.unity3d.com/Manual/UnityAnalyticsRemoteSettingsScripting.html
     
    Last edited: Feb 2, 2019
    FuntikStudio and Eiseno like this.