Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Simple example please, it doesn't work for me

Discussion in 'Unity Remote Config' started by hexaJer, Sep 16, 2019.

  1. hexaJer

    hexaJer

    Joined:
    Aug 26, 2018
    Posts:
    7
    Hi ! I tried to use it but I don't know if I did mistake or if it simple doesn't work.

    Unity 2019.1.6f1
    Remote Config 1.0.5


    upload_2019-9-16_18-9-56.png

    Code (CSharp):
    1.  
    2. ConfigManager.FetchCompleted += response =>
    3. {
    4.     if (response.status == ConfigRequestStatus.Success)
    5.     {
    6.         Debug.LogFormat("toto: {0}", ConfigManager.appConfig.GetString("toto"));
    7.         Debug.LogFormat("titi: {0}", ConfigManager.appConfig.GetInt("titi"));
    8.     }
    9.     else
    10.         Debug.LogError("Remote config : " + response.status);
    11. };
    12.  
    output is always 0 or null

    Thank you in advance.
     
  2. rambod

    rambod

    Unity Technologies

    Joined:
    Mar 2, 2018
    Posts:
    58
    Hi hexaJer!

    It's not 100% clear in the docs (we'll be updating it soon to be more clear), but ConfigManager.FetchConfigs needs to be called in order for Remote Config to fetch the config you need. Here's an example:

    Code (CSharp):
    1. public struct UserAttributes {
    2.     //any attributes you might want to use for segmentation, empty if nothing
    3. }
    4. public struct AppAttributes {
    5.     //any attributes you might want to use for segmentation, empty if nothing
    6. }
    7.  
    8. public class UseRemoteConfig : MonoBehaviour
    9. {
    10.     void Awake()
    11.     {
    12.         ConfigManager.FetchCompleted += response =>
    13.         {
    14.             if (response.status == ConfigRequestStatus.Success)
    15.             {
    16.                 Debug.LogFormat("toto: {0}", ConfigManager.appConfig.GetString("toto"));
    17.                 Debug.LogFormat("titi: {0}", ConfigManager.appConfig.GetInt("titi"));
    18.             }
    19.             else
    20.                 Debug.LogError("Remote config : " + response.status);
    21.          };
    22.         ConfigManager.FetchConfigs<UserAttributes, AppAttributes>(new UserAttributes(), new AppAttributes());
    23.     }
    24. }
     
  3. hexaJer

    hexaJer

    Joined:
    Aug 26, 2018
    Posts:
    7
    Thank you ! It work !

    The `Custom attributes are entirely optional` and // Optionally declare variables for any custom user attributes lines
    in the documentation suggest it's not required to declare userAttributes and appAttributes structs and fetch them.

    Perhaps comments placed here would be clearer.
    Code (CSharp):
    1.  
    2. // not here
    3. public struct userAttributes {
    4.     // Optionally declare variables for any custom user attributes:
    5.     public bool expansionFlag;
    6. }
    7.  
    8. public struct appAttributes {
    9.     // Optionally declare variables for any custom app attributes:
    10.     public int level;
    11.     public int score;
    12.     public string appVersion;
    13. }
    14.  
     
  4. hexaJer

    hexaJer

    Joined:
    Aug 26, 2018
    Posts:
    7
    It work but push config with editor randomly cause HTTP Bad Request error with really simple rules
    like `app.level==5` as condition and titi setting set to 5 instead of 2.
    push... error
    disable titi change in rule, push... it work
    re enable titi change, push... it work
    change titi = 6 in rule... error
     
  5. tagh

    tagh

    Unity Technologies

    Joined:
    Aug 16, 2017
    Posts:
    22
    @hexaJer Could you copy the Console error(s) you are encountering here please?