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

Remote Settings events not dispatched at all on build (but works great on editor)

Discussion in 'Unity Analytics' started by AlexKhundar, May 29, 2019.

  1. AlexKhundar

    AlexKhundar

    Joined:
    Mar 14, 2017
    Posts:
    19
    Hi there,

    It seems to be a weird issue. Everything works great on the Editor. Both RemoteSettings.Updated and RemoteSettings.Completed are dispatched and I have the right values (on the Editor, the development ones). But whenever I make a build, whatever the platform (PC / Android / iOS) and whatever the development build box is checked, I have neither of them.

    In order to test, I have those specifics logs
    Code (CSharp):
    1.     void Awake()
    2.     {
    3.         RemoteSettings.Completed += OnRemoteSettingsCompleted;
    4.         RemoteSettings.Updated += OnRemoteSettingsUpdated;
    5.     }
    6.  
    7.     void OnRemoteSettingsUpdated()
    8.     {
    9.         Debug.Log("REMOTE SETTINGS UPDATED");
    10.     }
    11.  
    12.     void OnRemoteSettingsCompleted(bool wasUpdatedfromServer, bool settingsChanged, int serverSuccess)
    13.     {
    14.         Debug.Log("REMOTE SETTINGS COMPLETED");
    15.     }
    I can see these logs in the Editor. But (for instance) after a PC development build, they do not appear on my outpug_log (even if I wait a couple of minutes). My Internet connection is great, and anyway, should be the same on my Editor and my PC build, right ?

    So, I can't find where is the issue.
     
  2. JeffDUnity3D

    JeffDUnity3D

    Joined:
    May 2, 2017
    Posts:
    14,446
  3. AlexKhundar

    AlexKhundar

    Joined:
    Mar 14, 2017
    Posts:
    19
    They do get updated when I change the dashboard and sync. And in the Editor, I do have the values I expect when I log them.
    I'm not yet using the Release settings. I'm focusing on making it work on Development since I can't make it work in any mode.
    According to the documentation, the HandleRemoteSettings function you are talking about is just a function which should be triggered by the RemoteSettings.Completed event, right ? And this event is supposed to be always dispatched, right ?
    I can't understand why it is the case in the Editor and not in Development build.

    So, you want me to do something like this ?
    Code (CSharp):
    1.         void Start()
    2.         {
    3.             RemoteSettings.Completed += HandleRemoteSettings;
    4.             HandleRemoteSeetings(false, true, -1);
    5.         }
    6.  
    7.         void HandleRemoteSettings(bool wasUpdatedfromServer, bool settingsChanged, int serverSuccess)
    8.         {
    9.             Debug.Log("HANDLE REMOTE SETTINGS");
    10.         }
    11.  
    I can explicitly call it like this. In the Editor, it is called twice. First time by explicit call and 2nd time by the event, I presume. On the build, it is called only once. Only by the explicit call.
    I'm surprised but as far as I tested on PC development build, even if the function is triggered only by the explicit call, the remote settings values are the ones I expect. But is it really reliable ? How can I know the request went well if I'm calling this explicitly ?
     
  4. AlexKhundar

    AlexKhundar

    Joined:
    Mar 14, 2017
    Posts:
    19
    I think I figured it out.
    The difference between the Editor and the build is the loading screen. In the Editor, I always start from my "Main" scene, in which there is my script in which I subscribe to the Completed event.
    So I think the request to the Analytics server is made in the same time as I start :
    - In Editor, I subscribe before I get the request response.
    - In build, the few seconds of loading make me subscribe after I get the request response.

    I thought this was not in the documentation, but it actually says : "You should register your handler functions for these events as early as possible during application launch, such as in the Awake() function of a MonoBehaviour loaded in your first Unity scene."
    Sorry I missed this part, this was totally my fault.

    Thanks for your patience !