[ad_1]
If the file is modified at edit time, and never modified within the constructed model of the sport, simply put the file someplace in your Assets listing such as you do with different property together with textures, fashions, scripts, and so on.
Files with the .JSON extension will routinely be imported as Textual contentAssets. (The identical goes for varied different extensions listed at that hyperlink, together with .txt, .bytes, .csv, .xml…) This allows you to load information out of the file utilizing the engine’s native referencing options, with out writing your individual file IO code or hard-coding any particular paths.
In the script that should use this JSON information, simply create a public or [SerializeField] variable of sort TextAsset. That offers you a slot within the Inspector the place you’ll be able to drag this JSON file to be referenced.
Doing it this manner, Unity’s construct course of and loading methods will be capable to see the place this file is referenced from, and guarantee it is loaded into reminiscence if you load a scene or prefab that references it – so that you need not fear about blocking or asynchronous file studying in your individual code. It additionally means you probably have gobs of those JSON information and a few are old-fashioned / unneeded / now not referenced wherever, the engine can detect that and strip them out so they do not add bloat or leak any growth secrets and techniques in your construct.
TextAssets additionally work with the Unity Addressable Assets system if you could load it dynamically or stream it from an asset bundle hosted on-line.
You can then get on the JSON textual content within the file with myJsonTextAsset.textual content and use the JsonUtility or different library of your option to parse it.
[ad_2]