Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by KupoMog · Jun 19, 2013 at 06:22 PM · buildserializationeditor-classes

Unity Pro: Using custom builds to set data before a build

I'm attempting to build my application by using MenuItem to create new menu build options, which run BuildPipeline.BuildPlayer() to create builds with different settings. Depending on which build I select, I'd like to change some data in various classes and have those changes carry over to the completed build. In essence:

 ------------
 // BuildProcess.cs : Editor class that sets data in BuildData class before creating a build
 ------------
 
 [MenuItem ("Build Process/iOS English Build")]
 public static void iOSEnglishBuild() {
     scenes = new string[] { "Assets/Scenes/myScene.unity" };

     // English version
     BuildData.SetIsInternational(false);
     
     // After data has been set, ready to build!
     BuildPipeline.BuildPlayer(scenes, "Builds/iOS", BuildTarget.iPhone, BuildOptions.AcceptExternalModificationsToPlayer);
 }

 [MenuItem ("Build Process/iOS International Build")]
 public static void iOSInternationalBuild() {
     scenes = new string[] { "Assets/Scenes/myScene.unity" };

     // International version
     BuildData.SetIsInternational(true);
     
     // After data has been set, ready to build!
     BuildPipeline.BuildPlayer(scenes, "Builds/iOS", BuildTarget.iPhone, BuildOptions.AcceptExternalModificationsToPlayer);
 }

 -----------
 // BuildData.cs : Stores data that is set right before building
 -----------
 
 using UnityEngine;
 using System.Collections;
 using System;
 
 [Serializable]
 public class BuildData : MonoBehaviour 
 {
     // References to descriptions for each region
     [SerializeField] public string[] englishData;
     [SerializeField] public string[] internationalData;
     
     // Are we using an international build?
     [SerializeField] private static bool isInternationalVersion;

     // Set from BuildProcess.cs
     public static void SetIsInternational(bool pIsInternational) 
     {
         isInternationalVersion = pIsInternational;
         Debug.Log("Set isInternational: " + isInternationalVersion);
     }

     // Called at runtime by a class who needs descriptions based on current region
     public string[] GetDescriptions()
     {
         if (isInternationalVersion)
             return internationalData;
         else
             return englishData;
     }
 }


Both builds are reporting that BuildData's isInternationalVersion is false. Is this a serialization issue? While doing a build, my debug log shows the data is being set to true, but then shows false once the build is run.

Should I be going about this in a different manner? I'm basically wanting to set certain flags when I select a build that will keep their states when the game is built. This is so that if I want to do, for example, an English vs. International build for my current project, I can just select a build option rather than manually changing some data in various scripts.

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

1 Reply

· Add your reply
  • Sort: 
avatar image
1
Best Answer

Answer by Adamcbrz · Jun 19, 2013 at 06:36 PM

I don't think you can accomplish what you want in this manner. Your best option is Platform Dependent Compliation. Check the bottom of the page under Custom defines. Here is the api for it:

http://docs.unity3d.com/Documentation/ScriptReference/PlayerSettings.SetScriptingDefineSymbolsForGroup.html

Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image KupoMog · Jun 19, 2013 at 07:16 PM 0
Share

This worked perfectly! Thank you. The custom defines are a clean, effective solution.

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

15 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Distribute terrain in zones 3 Answers

Build pipeline and wrong values in OnValidate / ISerializationCallbackReceiver 0 Answers

How to export Serialized Data with my Build 0 Answers

White Screen On Build 0 Answers

Run code after Build/Publish 0 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges