A recreated balance.json runtime loader view showing JsonUtility wrapper serialization from StreamingAssets.
A recreated balance.json runtime loader view showing JsonUtility wrapper serialization from StreamingAssets.

Move tuning variables into external configuration

Ball speeds, brick HP curves, and difficulty multipliers hardcoded in scripts require restarts or rebuilds for every minor adjustment. Storing values in StreamingAssets/balance.json lets designers edit numbers in plain text.

using System;
using System.IO;
using UnityEngine;

[Serializable]
public class StageConfig
{
    public int id;
    public int rows;
    public int baseHp;
}

[Serializable]
public class GameBalanceData
{
    public float baseSpeed = 13f;
    public float minElevationDeg = 12f;
    public float[] speedUpThresholds;
    public StageConfig[] stages;
}

Overcoming JsonUtility root array limitations

Unity's built-in JsonUtility cannot parse top-level JSON arrays directly. Wrap lists and arrays inside a container class to ensure fast, garbage-free native parsing.

using System.IO;
using UnityEngine;

public static class BalanceLoader
{
    public static GameBalanceData Load()
    {
        string path = Path.Combine(Application.streamingAssetsPath, "balance.json");
        if (!File.Exists(path))
        {
            Debug.LogWarning("balance.json not found, using defaults.");
            return new GameBalanceData();
        }

        string json = File.ReadAllText(path);
        return JsonUtility.FromJson<GameBalanceData>(json);
    }
}

Platform path handling

On Android, StreamingAssets resides inside the compressed APK/AAB package. Use UnityWebRequest or copy the config to Application.persistentDataPath on first boot for editable overrides.

Verification scope

Official documentation review

Verified

Reviewed the article's code and procedure against official Unity documentation and marked it ready for publication. This is not a claim of an independent Unity project or device reproduction; version- or device-specific reports will be checked in that environment as follow-up.

Official documentation checkedUnity StreamingAssets manual ↗