Search Unity

  1. Unity 6 Preview is now available. To find out what's new, have a look at our Unity 6 Preview blog post.
    Dismiss Notice
  2. Unity is excited to announce that we will be collaborating with TheXPlace for a summer game jam from June 13 - June 19. Learn more.
    Dismiss Notice
  3. Dismiss Notice

does each FetchConfigs fetch from the remote server?

Discussion in 'Unity Remote Config' started by laurentlavigne, Aug 4, 2020.

  1. laurentlavigne

    laurentlavigne

    Joined:
    Aug 16, 2012
    Posts:
    6,452
    I have the same script fetching remote config on various objects, there are maybe 4 or 5 of them sitting in the scene.
    Code (CSharp):
    1.         void Awake()
    2.         {
    3.             text.text = "data incoming...";
    4.             ConfigManager.FetchCompleted += ApplyRemoteSettings;
    5.             ConfigManager.FetchConfigs<userAttributes, appAttributes>(new userAttributes(), new appAttributes());
    6.         }
    Does each call to
    FetchConfigs 
    connect with the server?
    Is it better to call
    FetchConfigs
    once per scene and have other scripts

    ConfigManager.FetchCompleted += ApplyRemoteSettings;
    ?
     
  2. laurentlavigne

    laurentlavigne

    Joined:
    Aug 16, 2012
    Posts:
    6,452
    Reading ConfigManager.cs it seems that each FetchConfig sends a WebRequest and I'm not seeing any caching so I'd say optimizing this is up to us. correct?
     
  3. JeffDUnity3D

    JeffDUnity3D

    Joined:
    May 2, 2017
    Posts:
    14,446
    May I ask, why don't you combine everything into one request? Can you elaborate, sitting on the scene? In your code, you only have one. Or do you have each object calling that same code with that script attached to each object? You don't need to do that, clearly, if it's retrieving the same data each time. It would be better to have a single empty game object maybe called MyGameManager and put the Awake code once, in that object.
     
    laurentlavigne likes this.
  4. laurentlavigne

    laurentlavigne

    Joined:
    Aug 16, 2012
    Posts:
    6,452
    Thanks for confirming there is no caching so I went ahead and added a static variable alreadyFetched to avoid double fetching.
    Yes the remote config script is called on each gameobject.
    You're right that the clean way to do it is to centralize fetching but this way makes my work easy as I don't use RC to tune enemy stats yet.
     
  5. JeffDUnity3D

    JeffDUnity3D

    Joined:
    May 2, 2017
    Posts:
    14,446
    My point is that you only need to call it only once. Each call is retrieving the same data, not what you want and is not needed.