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
1
Question by Tetrad · Jan 28, 2011 at 09:52 PM · editorprefabsceneeditor-scripting

Is it possible to ensure that certain game objects don't get saved in the scene or otherwise hook into the default save scene to run custom editor code?

Basically I have some game objects that I'm using in a custom editor. It's a camera that points to a game objects and a render texture so that you can edit the definition for our NPCs and then have a preview of this object in the editor (using the render texture). We really want to keep this pattern because it helps our artists a lot to be able to see the changes they make to the item (equipment, etc). Making a bunch of prefabs for these NPCs isn't exactly an option for our data set and workflow.

Right now we have it set up such that when you close this custom editor the preview camera and object get removed from the scene. The problem is that if you have our custom editor open and then you save the scene you're currently editing, these game objects can begin to stat polluting the scene.

Right now we're semi-working-around-it by making the preview game objects destroy themselves on start, but ideally we could find a way to either 1) hook into the default "save scene" call to run custom code to check for these objects and delete them, 2) somehow otherwise ensure that these game objects don't get saved to the scene, or 3) use some other mechanism for rendering game objects to a texture for our editor other than putting a preview version of them in the current scene.

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

2 Replies

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

Answer by yoyo · Jan 28, 2011 at 09:57 PM

You can use this ...

gameObject.hideFlags = HideFlags.DontSave;

Which will prevent the objects from being saved, but leaves you on the hook for object management. If you generate objects and set the hideFlags to DontSave then the objects won't get serialized to your scene, but they will hang around in the editor until you delete them yourself.

I'm creating all my game objects under a single root object, and then using this code to clean up the scene in the editor after the game stops playing.

void OnDisable()
{
    if (Application.isEditor)
    {
        if (mRootGameObject != null)
        {
            // Object.Destroy is delayed, and never completes in the editor, so use DestroyImmediate instead.
            UnityEngine.Object.DestroyImmediate(mRootGameObject);
        }
    }
}

See docs for (a little bit) more info.

Comment
Add comment · Show 3 · 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 Tetrad · Jan 29, 2011 at 05:54 AM 0
Share

Looks like what I need. I'll try it when I get back to the office and accept if it works.

avatar image yoyo · Jan 29, 2011 at 07:06 AM 0
Share

Funnily enough I was just learning about it as you were asking your question, as I had a similar problem earlier today. First I thought DontSave was a panacea, then I discovered the caveat about needing to do your own object cleanup. The technique above did the trick for my use case, I hope it helps with yours.

avatar image vexe · Feb 19, 2014 at 02:11 PM 0
Share

until you delete them yourself.

Add to that: Or exit out the editor

avatar image
3

Answer by yoyo · Mar 21, 2011 at 06:46 PM

Note that you can also run custom code at asset save time using a SaveAssetsProcessor. This feature was added in Unity 3.2.

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

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

1 Person is following this question.

avatar image

Related Questions

Post-Process All Unity Scene GameObjects 1 Answer

Mark gameobject field as changed from prefab 2 Answers

How can I make function run in the editor only when I press a button in the inspector? 1 Answer

How to modify prefab permanently via script. 0 Answers

Display changes in the editor made to a prefab 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