Search Unity

Remote Settings, update handler NOT always dispatched?

Discussion in 'Unity Analytics' started by Matthewek, Apr 3, 2018.

  1. Matthewek

    Matthewek

    Joined:
    Apr 6, 2015
    Posts:
    49
    Hello, I am in a process of implementing Remote Settings into my new game, however after testing on Android (Unity 2017.3) I have noticed update handler is NOT always dispatched. Documentation says:

    I am using development mode in remote settings,

    Code (CSharp):
    1. void Start()
    2. {
    3.     adDelay = defaultAdDelay;
    4.     adMain = defaultAdMain;
    5.     adOnExit = defaultAdOnExit;
    6.     adMediate = defaultAdMediate;
    7.  
    8.     RemoteSettings.Updated += new RemoteSettings.UpdatedEventHandler(HandleRemoteSettingsUpdate);
    9. }
    10.  
    11. private void HandleRemoteSettingsUpdate()
    12. {
    13.     adDelay = RemoteSettings.GetFloat("adDelay", defaultAdDelay);
    14.     adMain = RemoteSettings.GetInt("adMain", defaultAdMain);
    15.     adOnExit = RemoteSettings.GetBool("adOnExit", defaultAdOnExit);
    16.     adMediate = RemoteSettings.GetBool("adMediate", defaultAdMediate);
    17.     nextToDisplay = GetAdvertType(adMain);
    18.     Debug.Log("[AD MANAGER] handled remote update");
    19. }
    Unfortunately on android device, update is often not dispatched, is that stable feature or I am doing something wrong?

    EDIT:

    What I also noticed, that even after settings were fetched once from the server (update fire) and I closed the app, opened it again (no update fired) thus not cached (previously fetched) settings but default were used.
     
    Last edited: Apr 3, 2018
  2. ap-unity

    ap-unity

    Unity Technologies

    Joined:
    Aug 3, 2016
    Posts:
    1,519
    @Matthewek

    I would recommend this code:

    Code (CSharp):
    1. void Start()
    2. {
    3.     RemoteSettings.Updated += new RemoteSettings.UpdatedEventHandler(HandleRemoteSettingsUpdate);
    4.     HandleRemoteSettingsUpdate();
    5. }
    6.  
    7. private void HandleRemoteSettingsUpdate()
    8. {
    9.     adDelay = RemoteSettings.GetFloat("adDelay", defaultAdDelay);
    10.     adMain = RemoteSettings.GetInt("adMain", defaultAdMain);
    11.     adOnExit = RemoteSettings.GetBool("adOnExit", defaultAdOnExit);
    12.     adMediate = RemoteSettings.GetBool("adMediate", defaultAdMediate);
    13.     nextToDisplay = GetAdvertType(adMain);
    14.     Debug.Log("[AD MANAGER] handled remote update");
    15. }
    The basic change is calling HandleRemoteSettingsUpdate from within Start, which would ensure the variables are set with the last values received and if no config file exists on disk, they will be set with the default values.
     
    JeffDUnity3D and Matthewek like this.
  3. erzhuben

    erzhuben

    Joined:
    Jul 26, 2018
    Posts:
    5

    But there is no Callback of Update also, and the remote value can't update by the code, please help!
     
  4. ap-unity

    ap-unity

    Unity Technologies

    Joined:
    Aug 3, 2016
    Posts:
    1,519
    Could you clarify your question?

    The Remote Settings will only be pulled when the app starts. That is by design.

    This thread is about some behavior that changed in 2017.x where the callback will now only be called if the settings are different than the cached version.
     
  5. erzhuben

    erzhuben

    Joined:
    Jul 26, 2018
    Posts:
    5

    I can got the development changed values, but can't got the release changed value when i changed the value on the Dashboard, and I restart or uninstall my app to test it, but it can't get the newest changed value. my unity is 2017.1.1p4.
     
  6. erzhuben

    erzhuben

    Joined:
    Jul 26, 2018
    Posts:
    5
    1. Need Add the remote code for the first scene!
    2. Warning the project id!
     
  7. ap-unity

    ap-unity

    Unity Technologies

    Joined:
    Aug 3, 2016
    Posts:
    1,519
    The Development configuration will only be sent to the Editor and apps marked as Development Builds. All other builds will get the Release configuration.

    Are you using Remote Settings via the Asset Store package or via scripting directly?
    Could you copy and paste the warning you are getting?
     
  8. erzhuben

    erzhuben

    Joined:
    Jul 26, 2018
    Posts:
    5

    I can get the release values now, and i want to mark the reason why can't get the value, and the one of the reason is my project id is the other project's, and the MonoBehaviour which used to update the value need add to the first scene.

    public class RemoteSettingsControl : MonoBehaviour {
    void Awake(){
    DontDestroyOnLoad(gameObject);
    }
    // Use this for initialization
    void Start () {
    Debug.LogWarning("RemoteSettingsControl start");
    RemoteSettings.Updated +=
    new RemoteSettings.UpdatedEventHandler(HandleRemoteUpdate);
    // HandleRemoteUpdate();
    }
    private void HandleRemoteUpdate(){
    Debug.LogWarning("RemoteSettingsControl Relase Test1="+ RemoteSettings.GetString("Test1","default"));
    }
     
  9. erzhuben

    erzhuben

    Joined:
    Jul 26, 2018
    Posts:
    5
    In the past two days, I have got flashback crashed, I am not sure if it is integrated with remote setting, could you help me to analysis the log, thanks.
    the log:

    09-06 09:57:39.788 10364-10502/? W/art: Native thread exiting without having called DetachCurrentThread (maybe it's going to use a pthread_key_create destructor?): Thread[52,tid=10502,Native,Thread*=0x8ede1100,peer=0x12ead100,"Thread-8971"]
    09-06 09:57:39.788 10364-10502/? A/art: art/runtime/thread.cc:1237] Native thread exited without calling DetachCurrentThread: Thread[52,tid=10502,Native,Thread*=0x8ede1100,peer=0x12ead100,"Thread-8971"]
    09-06 09:57:40.147 13528-10502/? A/google-breakpad: Microdump skipped (uninteresting)
    09-06 09:57:40.211 10364-10502/? W/google-breakpad: ### ### ### ### ### ### ### ### ### ### ### ### ###
    09-06 09:57:40.211 10364-10502/? W/google-breakpad: Chrome build fingerprint:
    09-06 09:57:40.211 10364-10502/? W/google-breakpad: 68.0.3440.91
    09-06 09:57:40.211 10364-10502/? W/google-breakpad: 344009100
    09-06 09:57:40.211 10364-10502/? W/google-breakpad: ### ### ### ### ### ### ### ### ### ### ### ### ###
    09-06 09:57:40.223 10364-10502/? A/libc: Fatal signal 11 (SIGSEGV), code 1, fault addr 0x9c in tid 10502 (Thread-8971)
    09-06 09:57:40.224 10364-10502/? A/libc: Unable to open connection to debuggerd: Connection refused
    09-06 09:57:40.319 786-1836/? D/ConnectivityService: ConnectivityService NetworkRequestInfo binderDied(NetworkRequest [ id=410, legacyType=-1, [ Capabilities: NOT_RESTRICTED&TRUSTED&NOT_VPN] ], android.os.BinderProxy@1cef109)
    09-06 09:57:40.319 786-905/? D/ConnectivityService: releasing NetworkRequest NetworkRequest [ id=410, legacyType=-1, [ Capabilities: NOT_RESTRICTED&TRUSTED&NOT_VPN] ]
    09-06 09:57:40.320 786-1836/? D/ConnectivityService: ConnectivityService NetworkRequestInfo binderDied(NetworkRequest [ id=409, legacyType=-1, [ Capabilities: INTERNET&NOT_RESTRICTED&TRUSTED] ], android.os.BinderProxy@8838f0e)
    09-06 09:57:40.320 786-1836/? D/ConnectivityService: ConnectivityService NetworkRequestInfo binderDied(NetworkRequest [ id=408, legacyType=-1, [ Capabilities: INTERNET&NOT_RESTRICTED&TRUSTED] ], android.os.BinderProxy@86e5d2f)
    09-06 09:57:40.321 786-1836/? I/WindowState: WIN DEATH: Window{8bc2f3c u0 SurfaceView}
    09-06 09:57:40.325 786-1834/? D/GraphicsStats: Buffer count: 6
    09-06 09:57:40.329 786-1835/? I/WindowState: WIN DEATH: Window{880d8e4 u0 com.crossword.puzzle.word/com.crossword.word.androidproject.MainActivity}
     
  10. mansiva2000

    mansiva2000

    Joined:
    Jul 2, 2013
    Posts:
    9
    @ap-unity

    I think we can achieve the same result by using the Completed callback and thus avoid potentially doing an update twice. Are there any drawbacks of doing it this way?

    Code (CSharp):
    1. void Start()
    2. {
    3.     RemoteSettings.Completed += RemoteSettingsUpdateCompleted;
    4. }
    5.  
    6. private void RemoteSettingsUpdateCompleted(bool wasUpdatedFromServer, bool settingsChanged, int serverResponse)
    7. {
    8.     someValue = RemoteSettings.GetInt("someValue", someValueDefault);
    9. }
     
  11. CharlesWard

    CharlesWard

    Unity Technologies

    Joined:
    Apr 19, 2017
    Posts:
    23
    @mansiva2000 I've added a discussion about the pros and cons of different ways of accessing your Remote Settings to the docs: https://docs.unity3d.com/Manual/UnityAnalyticsRemoteSettingsScripting.html

    The main drawback to using an event handler like Completed is that the settings aren't available immediately so parts of your code that rely on them have to wait for the asynchronous web request to either complete or timeout (i.e. the player has no internet).
     
    mansiva2000 likes this.
  12. Lesha-VH

    Lesha-VH

    Joined:
    Jul 3, 2012
    Posts:
    96
    Please, clarify when Remote Settings will be updated on client-side (on Android/iOS/Standalone if different)

    Or point me to documenation - I could find information.

    Should be app re-launched (remove from memory) on Android/iOS or only pause/resume is enough?

    When actual async fetch is performed?

    How to manually make request to RemoteSettings config?

    Thanks!
     
    Last edited: Oct 15, 2018
  13. tataygames

    tataygames

    Joined:
    Aug 4, 2016
    Posts:
    55
    The callback function is only calling the values when the app starts, is there a way when you updated your values on the site, there will be a callback to update the values? so players dont need to restart the app

    And another question is why development and release is not together? or why did development values cannot be push on release. like automatic so we dont need to input it on release tab. and worst case is we might get confuse and enter the wrong key or values while putting it on release tab.
     
  14. JeffDUnity3D

    JeffDUnity3D

    Joined:
    May 2, 2017
    Posts:
    14,446
    You should consider using Remote Config instead of Remote Settings. You can request updated values at any time https://forum.unity.com/forums/unity-remote-config.371/
     
  15. tataygames

    tataygames

    Joined:
    Aug 4, 2016
    Posts:
    55
    Is it available on unity 2017? Im might not possible to switch un unity 2019 :/
     
  16. JeffDUnity3D

    JeffDUnity3D

    Joined:
    May 2, 2017
    Posts:
    14,446
    Minimum required Unity version for the package is 2018.3