Course contentsShow
← Unity Game Development
Lesson 244 of 8284. Prefabs and Data ManagementFree lesson

Designing Flexible Level Configuration Profiles

Store level-specific parameters like spawn rates and environmental variables within ScriptableObjects to simplify scene design and setup.

In this lesson, you will learn how to centralize level-specific settings into modular ScriptableObject profiles to make your level design workflow more efficient and data-driven.

The Problem with Hardcoding

Previously, you might have placed variables like "Enemy Spawn Rate" or "Ambient Light Color" directly into a MonoBehaviour attached to a LevelManager in your scene. The issue? Every time you wanted to tweak the feel of a different level, you had to manually change those values on individual scene objects. This makes balancing a nightmare as your game grows.

The Solution: Level Configuration Profiles

Instead, we create a "Level Profile" ScriptableObject. Think of this as a template asset that lives in your Project folder, not the scene. By assigning this asset to your LevelManager, you can swap out the entire behavior of a level—from environmental variables to difficulty settings—just by pointing to a different file.

Here is how you define a simple profile:

using UnityEngine;

[CreateAssetMenu(fileName = "NewLevelProfile", menuName = "Level/Configuration Profile")]
public class LevelConfiguration : ScriptableObject
{
    public float spawnRate = 1.0f;
    public Color ambientLightColor = Color.white;
    public int maxEnemyCount = 10;
}

Implementing the Profile

By creating a LevelConfiguration asset, you can have "Level_Easy.asset," "Level_Hard.asset," and so on. Your LevelManager simply holds a reference to one of these files:

public class LevelManager : MonoBehaviour
{
    public LevelConfiguration currentProfile;

    void Start()
    {
        // Apply settings from the profile
        RenderSettings.ambientLight = currentProfile.ambientLightColor;
        // Use currentProfile.spawnRate to set your timers...
    }
}

This approach transforms your scene design. Instead of opening a level and hunting through Inspector tabs to adjust parameters, you simply select the appropriate ScriptableObject profile in your LevelManager. If you want to create a new, distinct level version, you don't need to rebuild logic—you just create a new asset file, adjust the sliders, and drag it into your scene. This decoupling separates the "what" (data) from the "how" (logic), ensuring your levels remain highly flexible and easy to balance.

Key Takeaway: By moving level variables into ScriptableObject profiles, you create reusable data assets that allow you to reconfigure entire scene parameters instantly without altering your core scripts.