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.
  2. Join us on Dec 8, 2022, between 7 am & 7 pm EST, in the DOTS Dev Blitz Day 2022 - Q&A forum, Discord, and Unity3D Subreddit to learn more about DOTS directly from the Unity Developers.
    Dismiss Notice
  3. Have a look at our Games Focus blog post series which will show what Unity is doing for all game developers – now, next year, and in the future.
    Dismiss Notice

Announcing support for JSON serialization for select Unity Editor assets

Discussion in 'Unity Remote Config' started by markychoi, May 29, 2020.

  1. markychoi


    Unity Technologies

    Aug 4, 2014
    We recently released a new preview version of the Remote Config package, version 1.3.2-preview.1, that makes it easier for you to implement Remote Config with select Unity Editor assets.

    These assets include TextAssets, ScriptableObjects, and custom MonoBehaviours attached to GameObjects. The updated Remote Config package includes new features and an updated GUI that allows you to drag-and-drop these assets into the JSON Editor modal. These assets are then automatically configured with Remote Config, minimizing the need for manual entry of key names and values. Finally, we provide a simple and uniform exposure and application of JSON at runtime.

    Let's say our code has a class CubeInfo as follows:
    Code (CSharp):
    1. [System.Serializable]
    2. public class CubeInfo
    3. {
    4.     public float rotateX = 10f;
    5.     public float rotateY = 10f;
    6.     public float rotateZ = 10f;
    7.     public float rotSpeed = 1.0f;
    8.     public Color color = Color.white;
    9. }
    Using the new Remote Config package, you can drag-and-drop any existing Text Asset that contains valid JSON to the Remote Config JSON Editor. In this particular example, using a Text Asset that already contains a structure that matches the CubeInfo class, all you would have to do to link it to Remote Config would be to drag that Text Asset into the modal:

    For ScriptableObjects, click on the upper right dot next to the selection box. Once you select any ScriptableObject, it should be automatically converted to JSON in Remote Config:

    Finally, if you select a GameObject from the scene, you will find all associated MonoBehavior Custom Scripts in the drop-down list in the JSON Editor modal. Select one from the list to convert it to JSON.

    Utilizing JSON at runtime as a string
    Applying those Settings to the CubeInfo object at runtime is straightforward. You can use the JsonUtility class for that purpose:
    Code (CSharp):
    1. case ConfigOrigin.Remote:
    3.     var jsonCubeString = ConfigManager.appConfig.GetJson("jsonCubeString");
    4.     JsonUtility.FromJsonOverwrite(jsonCubeString, CubeInfo);
    For more information, refer to the Utilizing Setting of type Json for overwriting objects in the Remote Config documentation.

    Feedback and Future Plans
    Looking forward, we are exploring additional ways to enhance your ability to work with JSON in the Unity Editor. This may include providing the ability to represent additional assets as JSON, including the default components (e.g., Transform, Box Collider, etc.) of a GameObject.

    Additionally, we are looking into ways to tighten the bindings of Editor objects and Remote Config. Two-way bindings ensures both the Editor object and Remote Config stays in sync. Our goal is to lower the barrier of entry for Remote Config integration, by reducing the amount of code needed to get started, and making as much of the Unity project remotely configurable by default.

    If you have feedback or ideas around JSON features you’d like to see, we definitely would like to hear from you. Feel free to respond in this forum or email us.

    For more information, refer to the latest Remote Config documentation. As always, you can reach us directly with any support questions or needs at
    vd_unity likes this.