# Where to store service urls for a Unity3D game

I have URL information for services (dozens of them) that I want to store in a Unity3D web player project. What is a good practice for storing it. (please don't say hard coding them)

I've recently joined a large scale Unity 3D project in the business world. I've noticed that there is no configuration file of any type. I.e. All URLs for service calls are hard coded. (among other configuration settings that are not typical for player editing)

While looking for a good solution to store/load, I'm seeing that: 1) Unity does not appear to have any kind of AppSettings. I.e. like Visual Studio dlls/exes/services might. (PlayerPrefs expressed in #3)

2) Web Player (which the project uses) does not support File IO, to store my own config.xml/config.json type file.

3) PlayerPrefs appears that it will remain isolated to the local machine. Updating the project does not replace the player prefs, and new variables are supposed to be hardcoded to populate the PlayerPrefs if those variables didn't already exist.

4) Hard Coding the values creates a hefty inconvenience, as we push our solutions from Dev to Test to Staging to Prod, we have to make sure to replace a code file. (typically systems are designed to change config files.) Additionally, once the code was built, we wouldn't be able to reasonably change the settings to experiment with different servers or other configuration changes.

What would you recommend?

• I also have this same question on the LinkedIn Unity Group, and also on the Unity Scripting forum. --> I will repost the solution from the others if they have it first. – Dan Violet Sagmiller Jan 2 '15 at 14:20
• Presently I'm leaning towards a Settings class with a dictionary. The settings will attempt to be populated from JSON, and attempt 2 paths. 1) it will try to load from a File IO, to find a JsonSettings.dat file, which works in everything but Web, and 2) it will attempt to send a JS Network message out to the page it is hosted in, to get the JSON settings from it instead, which only works in the web. In either case it is a JSON file, it has 2 locations it needs to live. but that I think might be the best solution at present. – Dan Violet Sagmiller Jan 2 '15 at 14:34

We actually got over this problem in a non-game application by using an XML file (you could also use JSON if you prefer). This is compiled into our application so we don't use IO for it, we instead use XML. This does obviously mean you have to re-compile when making changes though.

Our file looked something like this:

services.xml

<services serverURL="https://services.our-api-url.com">
<service>
<label><![CDATA[GETSTATUS]]></label>
<url><![CDATA[/status]]></url>
<method><![CDATA[GET]]></method>
<type></type>
</service>
<service>
<url><![CDATA[/session]]></url>
<method><![CDATA[POST]]></method>
<type></type>
</service>
<service>
<label><![CDATA[LOGOUT]]></label>
<url><![CDATA[/session]]></url>
<method><![CDATA[DELETE]]></method>