What are the common use cases in which Object’s hideFlags is set to DontSave?
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
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.)