Member-only story

Unity: Reading external JSON files

Allison Liemhetcharat
7 min readJan 19, 2021

--

I recently wrote a guide on reading external XML files in Unity. From some discussion in a Reddit post I made, I learned that Unity also has built-in support from JSON files, and there may be performance benefits to using JSON files instead of XML files. Hence, after considering to switch Mystery Queen over to using JSON files, I decided to write a parallel article — this one — about reading external JSON files in Unity. The content and structure of this article will be almost identical to the XML one, except that code snippets and some explanations have been changed.

We can do a lot with the Unity editor, such as changing a game object’s / component’s attributes, and we can do a lot with custom C# scripts, such as the behavior of an object. For example, we can have some text appear on screen when the character walks into a pre-defined region.

Alfred triggers a chat with Elise when she walks near him.

While the above example can be created entirely with the Unity editor and C# behavior, sometimes it is useful to be able to define some of the attributes externally via JSON files. For example, perhaps we want to release the game in multiple regions around the world with different languages. It is much easier to go through a list of JSON files and change the text, than to inspect the multitude of game objects, and seeing where there are text to switch. Also, with JSON files, the game logic remains the same, and we can…

--

--

Allison Liemhetcharat
Allison Liemhetcharat

Written by Allison Liemhetcharat

Proud mom, roboticist, software engineer.

No responses yet