Skip to content
Tutorials Center
My learning

Topics

Lesson 32 of 36 ยท Optimization and Publishing

Building and Publishing Your Unity Game

Build a Unity game for Windows, Android, iOS and WebGL - Build Profiles, scenes, player settings, scripting backends, saving data, versioning and store release checklists.

A game that only runs in the Editor is not finished. Unity can build for desktop, mobile, web and consoles from one project, but every platform has its own settings, limits and store rules. This lesson walks through the build process, the settings that matter, how to save player data safely, and a checklist for releasing.

Unity itself is not available on this page, so the steps are described in text, the C# is read-only, and the runnable stand-ins cover versioning and save-data logic you can reuse.

Build Profiles and scenes

In Unity 6 open File > Build Profiles (older versions: Build Settings). A build profile stores a platform and its settings, so you can keep, say, Windows Development, Windows Release and Android side by side. The important parts:

  • Scene List: the scenes included in the build, in order. Index 0 loads first. A scene not in this list cannot be loaded with SceneManager.LoadScene.
  • Platform: switch to the target (Windows/Mac/Linux, Android, iOS, WebGL, consoles). Switching reimports assets, so do it early, not on release day.
  • Development Build: turns on the Profiler connection, script debugging and detailed error output. Never ship it.
  • Scripting defines, such as UNITY_EDITOR, UNITY_ANDROID and DEVELOPMENT_BUILD, let one code base behave differently per platform:
C#
void Start()
{
#if UNITY_EDITOR
    Debug.Log("Running in the editor");
#elif UNITY_ANDROID || UNITY_IOS
    Application.targetFrameRate = 60;
#endif
}

Prefer the runtime check Application.platform or Application.isMobilePlatform when you can; use #if when the code does not compile on some platform.

Player settings

Edit > Project Settings > Player holds the identity and platform options:

  • Company Name, Product Name, Version: shown to the player and used in the save path (Application.persistentDataPath).
  • Icon and Splash Screen.
  • Resolution and Presentation: fullscreen mode, default window size, orientation on mobile.
  • Scripting Backend: Mono (fast iteration, JIT) or IL2CPP (C# translated to C++; required for iOS and consoles, faster at run time, slower builds). Set the API Compatibility Level to .NET Standard 2.1 (or the .NET Framework profile Unity recommends).
  • Managed Stripping Level: removes unused code to shrink the build; use [Preserve] for code reached only by reflection.
  • Color Space: Linear.
  • Android: package name (com.company.game), minimum API level, ARM64 target, App Bundle (.aab) for Google Play, keystore for signing. iOS: bundle identifier, signing team, build from Xcode.

Quality settings

Project Settings > Quality defines levels (Low, Medium, High). Each sets shadow distance and resolution, anti-aliasing, texture quality (mip skipping), vsync and LOD bias. Choose per platform and let the player switch with QualitySettings.SetQualityLevel(i). See Profiler and optimization for what to test.

WebGL and other targets

  • WebGL runs in the browser through WebAssembly. Builds are large and load slowly, so enable compression (Brotli or gzip, with matching server headers), strip unused code, and use texture compression. Threads and some APIs (sockets, System.IO outside the virtual file system) are limited, and audio starts only after the first click. PlayerPrefs saves to IndexedDB.
  • Desktop: the simplest target. Ship as a folder or an installer; Steam adds Steamworks.
  • Mobile: test on real devices, handle app pause and resume (OnApplicationPause), thermal limits and varied aspect ratios.

Saving player data

Players expect progress to survive quitting. Options:

  • PlayerPrefs: key-value store for settings (volume, last level). Simple, not for large or sensitive data.
  • JSON files in Application.persistentDataPath: the standard for saves. JsonUtility serializes public fields and [Serializable] classes.
C#
using System;
using System.IO;
using UnityEngine;

[Serializable]
public class SaveData
{
    public int version = 2;
    public int level = 1;
    public int coins;
    public float[] bestTimes = new float[0];
}

public static class SaveSystem
{
    static string Path => System.IO.Path.Combine(Application.persistentDataPath, "save.json");

    public static void Save(SaveData data)
    {
        string tmp = Path + ".tmp";
        File.WriteAllText(tmp, JsonUtility.ToJson(data, prettyPrint: true));
        if (File.Exists(Path)) File.Delete(Path);
        File.Move(tmp, Path);                 // write to a temp file first so a crash cannot corrupt the save
    }

    public static SaveData Load()
    {
        if (!File.Exists(Path)) return new SaveData();
        try { return JsonUtility.FromJson<SaveData>(File.ReadAllText(Path)); }
        catch { return new SaveData(); }
    }
}

Two habits protect players: write to a temporary file and then replace the real one, and include a version number so later game updates can migrate old saves. The stand-in below does the migration part and shows how a save can be validated.

C# Stand-in: versioned save migration

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with Console.ReadLine()), it gets the next line from this box.

Never trust a save file blindly: players edit them and files get corrupted. Validate ranges and fall back to defaults. For competitive games keep important state on a server, since client-side saves can always be changed.

Versioning

Use semantic-style versions (1.2.0) for the Player Version and a monotonically increasing build number (Android Bundle Version Code, iOS Build), because stores reject a lower number than the last upload. The stand-in compares versions the way an update checker would.

C# Stand-in: version comparison

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with Console.ReadLine()), it gets the next line from this box.

Release checklist

  1. Test a Release (non-development) build on the weakest target device, not just the Editor.
  2. Remove debug UI, cheats and Debug.Log spam (logging is slow; strip with [Conditional] or log levels).
  3. Check the Player Log for errors (%USERPROFILE%\AppData\LocalLow\Company\Product\Player.log on Windows).
  4. Add crash reporting and basic analytics, with privacy consent where law requires it.
  5. Review store requirements: icons, screenshots, age rating, privacy policy, target API levels, 64-bit.
  6. Keep your signing keys safe and backed up; losing an Android keystore means you cannot update the app.
  7. Use version control (Git with the Unity .gitignore, Library/ excluded) and tag every release.
  8. Automate builds with Unity Build Automation or batch mode (Unity -batchmode -buildTarget Android -executeMethod Builder.Build).

Check your understanding

Quick check ยท 4 questions

of 4 answered You scored / 4 ยท perfect!

  1. 1. A scene is missing from the scene list. What happens when you call SceneManager.LoadScene on it in a build?

    Only scenes in the build's scene list are packaged and loadable.
  2. 2. Which scripting backend is required for iOS?

    Apple does not allow JIT compilation, so iOS builds use IL2CPP.
  3. 3. Why write a save to a temporary file and then replace the old one?

    If writing is interrupted, the original save is still intact.
  4. 4. Why compare versions with System.Version instead of plain strings?

    Text comparison goes character by character; numeric parts must be compared as numbers.

Summary

  • Build Profiles bundle platform settings; the scene list decides what can be loaded.
  • Player and Quality settings control identity, scripting backend (Mono or IL2CPP), stripping and graphics level.
  • Save with JSON in persistentDataPath, write atomically, include a version and validate on load.
  • Test a release build on real, low-end devices and follow each store's checklist before shipping.

Next: Project: A 2D Platformer