I’ve been having trouble finding ways to import config files into my Unity project. I would like to either use JSON or Yaml formats to import static data into my project.
I found Unity’s JSONUtility library but my goal isn’t to serialize/deserialize classes. My only intent is to add data to the config and import it at runtime. For example data like the run_speed of a character, instead of putting that directly into a script or making it a [SerializeField] in the script I would rather import at runtime and set the value accordingly.
Whats the best way to achieve this? Is this is a common convention in Unity or should I take a different approach to accomplish this goal?
The problem I’m trying to solve is having to rebuild a project anytime I want to change any data. With the above example I could modify the run speed of the player through the config and not have to rebuild the project.
I use json files for data all the time like that. I simply download the file at the start and deserialize it or use a JObject to parse out the data I need. No matter what you do, you’ll have to find a way to parse out the data.
Serialization is just a part of the process of saving/loading, at some point you have to know how your data is going to look like in binary.
The JSONUtility or any other JSON, XML, CSV, binary utility is going to perform that part, before saving/after loading the bytes that represent your data.
So you want to use some sort of serialization. And most preferably a data type that’s set up for such a serializer.
Yep, as @Brathnann said, UnityRemoteConfig will do the trick, but, are you sure you really want to do this? If this is for testing purposes only, then it’s fine, but, do you really want to be able to change the speed of the player in real-time online? The speed of the player is related to everything in the game, from expected time to complete the level to level difficulty, etc. It just seems to me that if you change the speed of the player, you also have to think about how it affects almost every other section of your game.
I was wondering that myself :). This is my first time using Unity, my game development experience comes from using raw C++ and OpenGL (no game engine). Using configs was huge for us as compiling all the source code takes a while and testing would be painful.
Of course using a game engine is a bit different and that isn’t really an issue. I was wondering what the convention was, do Unity developers typically use config files in this sense? A part of me still feels it would be good practice, but at the same time it feels unnecessary. What do you all think?
Are you talking about local configs or online configs? Local configs can be used quite often, but for some general game settings, like game difficulty, audio range, etc (just regular stuff you’d usually find in the options menu).
Online configs (or in this case, Unity Remote Settings) are generally used when you want to change stuff not related to core gameplay in real-time. For example, your game might have different “skins” on certain holidays (Winter, Christmas, etc.), you could use Remote Config to specify what skin is currently active so that all players can see it at the same time.
If you don’t use Unity Remote Settings, you could use your server that stores files (S3 or something). Maybe you have a .json file of all prices in your in-game store, you could check that .json file every time the user opens the store so they could see any changes to it if you ever decide to update it in real-time. Generally, online configs are used for stuff that you absolutely need to update without having to force a build of your app in order to get it to all users.