Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.

Question Best way to access build configuration vars (in server.json?)

Discussion in 'Game Server Hosting' started by gogogotchi, Jun 20, 2023.

  1. gogogotchi


    Mar 21, 2023
    Hey all!

    Been reading the docs and am trying to find the best way to read our build configuration variables into our dedicated server on startup. I also wasn't sure exactly when to do the reading because the docs say the build configuration variables are written to the server.json file after startup.

    Basically, our use case is that we'd like to connect to an external data source, and would like to put the host, port, credentials into configuration variables (similar to how we put them into kubernetes secrets in our other services - although I realize these aren't necessarily secrets as GSH build config vars - though would be nice if they were) - and connect to said service when the game server starts up.

    A bit surprised I haven't been able to find a sample class for this... although I do see a ServerConfigReader in the Multiplay sdk, then I see a reference "MultiplayService.Instance.ServerConfig.AllocationId" in the BR200 code - but this ServerConfig class won't let me get at my custom variables...

    Are there any insights as to best practices in this regard?
  2. jackward84


    Jan 26, 2017
    Also looking for an answer to this. I don't care if I have to parse server.json directly but I can't even find where it is.

    Docs state where it is IF you are using a container.

    If not using a container, it says the file is relative to the binary in the "Server ID" folder. But doesn't mention what a "server ID folder" is.

    Guess I could trawl the filesystem to find out...
  3. jackward84


    Jan 26, 2017
    I found it, I had an inkling it was there from the docs but didn't trust it.

    Code (CSharp):
    1.         var home = Environment.GetFolderPath(Environment.SpecialFolder.UserProfile);
    2.         var serverJsonFile = Path.Join(home, "server.json");
    3.         if (File.Exists(serverJsonFile))
    4.         {
    5.             var serverJson = File.ReadAllText(serverJsonFile);
    6.             Debug.Log(serverJson);
    7.         }
    gogogotchi likes this.