• 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
3
Question by YoungDeveloper · Jul 20, 2015 at 01:09 AM · buildsceneexclude

Exclude gameobjects from final build

I have scene with certain gameobjects, some of them are development related only and i'd like to not include them in final build. Is it possible to exclude certain gameobject with their c$$anonymous$$lds from final builds. For now the only solution i see is deleting the gameobjects, build and undo, but that doesnt really seem very practical and safe.

Comment
Add comment · Show 5
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 meat5000 ♦ · Jul 20, 2015 at 01:18 AM 1
Share

If you are pressed for time you can

 if(!Application.isEditor)
 {
     Destroy(gameObject);
 }

until you find a better solution.

Alternatively, Save a Dev and Release version of the Scenes themselves rather than relying on going back and forth between versions within the same file. Thats asking for trouble.

Using samizzo's answer below for example, Perform his process on your Dev build and when complete save it as release.

A little editor script to find all objects marked with a tiny identifier script which removes them then saves a 'Release' Scene file - ideal. Then you can just double click Dev version and keep working.

avatar image YoungDeveloper · Jul 20, 2015 at 02:17 AM 0
Share

That's cheap haha, but that data must be removed from build though. For now i see one solution which could be an editor script who prepares for build and later un-prepares. Storing that data in editor or editor utilities folder as prefabs, so it wouldn't be included in final build. I was hoping there are some events or methods in build process. I know there are assets which can obfuscate scripts on build, thought there might be something different with scene data preprocessing.

avatar image meat5000 ♦ · Jul 20, 2015 at 02:39 AM 1
Share

prepares for build and later un-prepares.

This is what I was getting at. If your scenes are 1, 2, 3, name them 1Dev, 2Dev, 3Dev and have your editor script save off 1, 2, 3 as the release versions. You never need to open those, just have the script reload your xdev scene after its process. No reverting hectic death nonsense to worry about.

All you need is a blank script called Killscript and have your editor script look for all instances in scene.

Editor script should:

Save scene as Copy.

Load Copy.

Find instances of script, kill said objects.

Save Scene.

Load original.

I think it'll take about an hour to put together :P Worth it if you intend to redo the process.

avatar image YoungDeveloper · Jul 20, 2015 at 02:58 AM 0
Share

Yeah, something like I was thinking first, but scene copying is a bit of overkill i think. It could just loop through build scenes and look for that gameobjects and save them as prefabs in editor. Later unpack and place.

But it depends on the setup really, maybe thats why we think about this differently lol. I have one gameobject which acts as parent and rest of the cake is inside as childs, so its perfect as single prefab.

Yeah, not more than 20 min script I'd say lol, just wanted to be sure if there aren't any hooks for build pipeline.

Thank for the input

avatar image samizzo · Jul 20, 2015 at 06:47 AM 0
Share

There don't seem to be any hooks unfortunately! The build pipeline seems lacking in extensibility in that way. But if you do what I suggested, you can load the levels and destroy the GameObjects (you have to call DestroyImmediate though, not Destroy).

3 Replies

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

Answer by zach-r-d · Jul 28, 2015 at 06:59 PM

Actually, t$$anonymous$$s is exactly what the EditorOnly tag is for. If tagged using the built-in EditorOnly tag, a game object will appear in the editor (including playmode, I believe) but will be removed in any actual builds.

Assuming it's okay to change the tag of the game object, anyway. Otherwise your best bet is to use an OnPostProcessScene callback that removes unwanted game objects right before the scene is built.

It's probably too late given the age of t$$anonymous$$s question, but for anyone who stumbles across t$$anonymous$$s thread in the future, these ways are probably the easiest.

Comment
Add comment · Show 4 · 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 samizzo · Jul 28, 2015 at 11:19 PM 1
Share

That's great info, I didn't know about that tag! Thanks very much!

avatar image Fr33zerPop · Jun 14, 2018 at 07:03 PM 0
Share

Good info is never too old if it's still relevant! I wonder how it relates to the 2018.1 build that I'm using... Anyone with an update to this functionality?

avatar image Privateer · Jul 17, 2018 at 08:17 AM 0
Share

At 2018.2, EditorOnly tag is still there. I don't see it going away any time soon.

avatar image Stratosome · Jul 17, 2018 at 08:20 AM 0
Share

That's pretty cool. Didn't know about that. I'll have to keep it in mind!

avatar image
2

Answer by samizzo · Jul 20, 2015 at 02:02 AM

I don't t$$anonymous$$nk there's any nice way to do t$$anonymous$$s in Unity at the moment. What you would have to do is to create your own menu item or GUI somewhere w$$anonymous$$ch triggers a build via the BuildPipeline. That way you can perform some processing before building, for example, load a level and delete objects, and then kick off the build. You will want to make sure that you switch to a new empty scene after the build finishes, otherwise if you leave the level open, it will have your modifications in it and you might accidentally save them.

You can use EditorBuildSettings.scenes to get a list of all scenes that have been added to the project (however, the documentation seems to be missing for t$$anonymous$$s on the Unity web site).

Another way to do t$$anonymous$$s is to use conditional compilation to include code only when in the editor (that won't work if you really do need to get rid of the entire GameObject though).

Comment
Add comment · 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
2

Answer by grimmdeveloper · Jul 20, 2015 at 08:55 AM

Scripts in the WebPlayerTemplate don't get compiled, maybe the same for gameobjects?

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 YoungDeveloper · Jul 22, 2015 at 06:33 PM 0
Share

Yeah, same with Editor and Editor Default Resources folders,i wrote the solution using Editor folder.

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.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

31 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 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 avatar image

Related Questions

Distribute terrain in zones 3 Answers

Two versions of one game on a single project 1 Answer

LoadLevelAdditiveAsync by index? 1 Answer

Excluding resources when building 2 Answers

Build just what's in the scene? 1 Answer


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