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
2
Question by Superboonie88 · Sep 01, 2012 at 05:55 PM · objectruntimehideflags

When do you use DontSave for Object's hideFlags?

What are the common use cases in which Object's hideFlags is set to DontSave?

Comment
Add comment · Show 4
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 Scribe · Sep 01, 2012 at 07:16 PM 0
Share

Temporary objects, You might use them if you are writing an editor extension to help visualise things in the scene view (such as an object to show a waypoint) which you don't want to save as an actual object.

avatar image Superboonie88 · Sep 01, 2012 at 08:06 PM 0
Share

Scribe, can you answer below so I can accept your answer?

avatar image Scribe · Sep 01, 2012 at 08:55 PM 0
Share

Sure, glad it was helpful to you :)

avatar image Superboonie88 · Sep 02, 2012 at 01:13 AM 0
Share

Very helpful indeed, thank you.

2 Replies

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

Answer by Scribe · Sep 01, 2012 at 08:55 PM

Reposted as an answer at the request of Superboonie88!

Temporary objects, You might use them if you are writing an editor extension to help visualise things in the scene view (such as an object to show a waypoint) which you don't want to save as an actual object.

Scribe

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 Bunny83 · Sep 02, 2012 at 01:25 AM 2
Share

Yes, it's actually only used inside the editor. Since this is the only place where assets / data is serialized / saved. At runtime you can't "save" any assets or objects.

The best example is the camera for the SceneView which is attached to an invisible gameobject (HideAndDontSave). This gameobject is created when the sceneview is opened. Since it's a gameobject it is inside the current scene, but it isn't saved. It's also used for many other editor resources like textures for the GUI.

avatar image
1

Answer by yoyo · Dec 03, 2015 at 12:55 AM

Almost never.

HideFlags.DontSave probably doesn't mean what you think it means. The documentation states:

The object will not be saved to the scene. It will not be destroyed when a new scene is loaded. It is a shortcut for HideFlags.DontSaveInBuild | HideFlags.DontSaveInEditor | HideFlags.DontUnloadUnusedAsset.

It is your responsibility to cleanup the object manually using DestroyImmediate, otherwise it will leak.

In other words, this should only be used when you are creating an object which you do not want saved, and you do not want it unloaded when the scene changes, and you are going to destroy the object manually yourself. (Note that Destroy is fine, you don't have to use DestroyImmediate.)

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 Bunny83 · Dec 03, 2015 at 04:07 AM 1
Share

Your answer is a bit misleading. As Scribe said in his answer the hideflags are actually only relevant to editor program$$anonymous$$g as Unity doesn't (and actually can't) save anything at runtime / in a build game. Inside the editor you can't use Destroy as it's delayed to the end of the current frame. Inside the editor the runtime doesn't run so it can't be completed. If you use Destroy in the editor you will get an error and the object won't be destroyed. You have to use DestroyImmediate inside editor code.

avatar image yoyo Bunny83 · Dec 03, 2015 at 06:35 AM 0
Share

While my answer might be slightly misleading, I$$anonymous$$HO it's not as misleading as the "DontSave" name of this flag. In particular, the "DontUnloadUnusedAsset" behaviour is quite surprising. I may have been feeling reactionary when I posted my answer, as today I discovered that our game is leaking objects because "DontSave" seemed like the right way to handle dynamically created objects. I stand by my answer and think Unity should remove the DontSave compound flag and require users to select the flags they actually need. Fair point about DestroyImmediate in editor, though the documentation should be much more clear about this.

avatar image Bunny83 yoyo · Dec 03, 2015 at 02:51 PM 0
Share

I can't think of any usecase of "hideFlags" at runtime. As said the hideflags are for in editor use only. They make no sense at runtime. Even when "DontUnloadUnusedAsset" works at runtime, it makes no sense to use it. It will only affect objects which aren't referenced by any managed object anymore. So you would have to use FindObjectsOfType to regain access to those objects.

If an object might be used in the future, you want to keep a reference to it somehow. If you have a reference it won't be unloaded.

Just as reference the HideFlags documentation says:

Bit mask that controls object destruction, saving and visibility in inspectors.

The example code over here is complete nonsense. You'll never use hideflags at runtime since it's pointless.

I've written a hideflags editor window which can edit the hideflags of selected objects and also has a "hidden object explorer" at the bottom so you can select a hidden object as well and make it visible.

Show more comments

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

10 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

Related Questions

Changing a second objects material on trigger 0 Answers

Object disappear when position changes at runtime 0 Answers

Use more than a hideflag 1 Answer

Have a Timer Counts To 5 sec. Then Make a Sphere Appear While Using Instantiate 1 Answer

object can't be null when highlighted in the inspector? 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