A flexible package for managing different configurations (flavors) of your Unity application.
Unity Flavors provides an easy way to maintain multiple variants of your application from a single codebase. This is particularly useful for:
- Managing different build configurations (development, staging, production)
- White-labeling your application with different branding
- Creating free/premium versions with different features
- Handling region-specific customizations
- Simple flavor creation and switching
- Automatic define symbols for conditional compilation
- Easy access to flavor-specific properties at runtime
- Editor integration for seamless workflow
- Configurable app identifiers, version numbers, and icons per flavor
Open the Package Manager window, and click the + icon, then click on Add package from git url. Copy and paste the following url and click Add:
https://github.com/Sov3rain/unity-flavors.git?path=/Assets/unity-flavors#1.0.0
This will tag the package with a specific version.
You can also install the SDK by downloading the .unitypackage
from the releases page and importing it into your project.
Before creating any flavors, you need to initialize the Flavor Manager:
- In the Unity menu, select
Flavors > Create Flavor Manager
- This will create a FlavorManager asset in your Resources folder
- In the Unity menu, select
Flavors > Create Flavor
- Enter a name for your flavor (e.g., "Development", "Production", "FreeVersion")
- Click either "Create" or "Create and set as current"
- In the Unity menu, select
Flavors > Select Flavor
- Click on the flavor you want to apply
Select a flavor asset in your Project window and configure its properties in the Inspector:
- Product Name: The name of your application
- Bundle Version: The version string of your application
- Bundle Identifier: The application identifier (e.g., "com.company.app")
- Icon: The application icon
- Properties: Key-value pairs for flavor-specific runtime configuration
Flavors automatically create preprocessor directives based on the flavor name in the format FLAVOR_FLAVORNAME
. You can use these to conditionally compile code:
// This code will only compile when the "Development" flavor is active
#if FLAVOR_DEVELOPMENT
Debug.Log("Running in development flavor");
// Enable development-only features
#endif
// Different code paths for different flavors
#if FLAVOR_PREMIUM
// Premium version features
EnablePremiumFeatures();
#elif FLAVOR_FREE
// Free version features
ShowAds();
#endif
// Combining with other preprocessor directives
#if UNITY_ANDROID && FLAVOR_CHINA
// China-specific Android code
InitializeChineseServices();
#endif
Define properties in your Flavor asset's inspector, then access them at runtime:
using UnityEngine;
using UnityFlavors;
public class ExampleComponent : MonoBehaviour
{
void Start()
{
// Get string properties
string apiUrl = FlavorManager.Instance.GetString("ApiUrl", "https://default-api.com");
string welcomeMessage = FlavorManager.Instance.GetString("WelcomeMessage", "Hello!");
// Get numeric properties
int maxUsers = FlavorManager.Instance.GetInt("MaxUsers", 10);
float cooldownTime = FlavorManager.Instance.GetFloat("CooldownTime", 5.0f);
// Use the properties
Debug.Log($"Welcome message: {welcomeMessage}");
Debug.Log($"API URL: {apiUrl}");
Debug.Log($"Max users: {maxUsers}");
Debug.Log($"Cooldown: {cooldownTime}s");
}
}
You can check which flavor is currently active:
using UnityEngine;
using UnityFlavors;
public class FlavorChecker : MonoBehaviour
{
void Start()
{
if (FlavorManager.Instance.IsCurrentFlavor("Development"))
{
Debug.Log("Running Development flavor");
}
// Display current flavor name
Debug.Log($"Current flavor: {FlavorManager.Instance.Current.name}");
}
}
- Create a default flavor - Always have a default flavor with sensible defaults
- Use common property keys - Maintain consistency in property keys across flavors
- Organize flavor assets - Keep flavor assets in a dedicated folder
- Document your flavors - Keep notes on what each flavor is for
- Test all flavors - Regularly test builds with different flavors
If preprocessor directives aren't working:
- Select
Flavors > Refresh Define Symbols
from the menu - Ensure your flavor name doesn't contain special characters
- Check if the flavor is properly set as current
If your properties aren't accessible at runtime:
- Make sure the FlavorManager asset is in the Resources folder
- Verify that the property keys match exactly (case-sensitive)
- Check that you've properly set a current flavor