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 Deadcow_ · Jul 03, 2015 at 05:58 AM · sceneserializationsave scenedirty

Set Dirty and Save Scene

Hi. I had wrote a custom inspector for some class Container. This class contains an array (public) of serializable class ContainerItem. From my custom inspector I vary this array, and if some changes to this array applied I use EditorUtility.SetDirty(container);

This works just fine, items added through inspector are there on playmode and after. But. But if I add item and close Unity changes not saved. And if I add item and click Ctrl+S (although unity not saying there were changes on scene), then item is saved after reset.

I'm not too experienced with custom inspectors and serialization and whatewer. Why unity not saying there are changes at scene to save? How to force editor to save scene or to track changes? I just need it at least to remind me to save changes.

Comment
Add comment · Show 6
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 sathya · Jul 03, 2015 at 06:07 AM 0
Share

Are you using Scriptable Objects ? If so try using AssetDatabase.SaveAssets();

avatar image Deadcow_ · Jul 03, 2015 at 06:11 AM 0
Share

No, in this case my Container is $$anonymous$$onoBehaviour and ContainerItem is serializable class with no inheritance

avatar image sathya · Jul 03, 2015 at 06:16 AM 0
Share

Extend the ContainerItem with ScriptableObject and try the same.

avatar image sathya · Jul 03, 2015 at 06:21 AM 0
Share

https://unity3d.com/learn/tutorials/modules/beginner/live-training-archive/scriptable-objects

avatar image Deadcow_ · Jul 03, 2015 at 08:11 AM 0
Share

Thanks. I use ScriptableObjects for many things in my projects. Just thought that'll be too cumbersome in this case.

I form the full answer as an Answer below :)

Show more comments

1 Reply

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

Answer by Deadcow_ · Jul 03, 2015 at 08:11 AM

Thanks. I use ScriptableObjects for many things in my projects. Just thought that'll be too cumbersome in this case.

So, I decided to use SerializedObjects instead

 var serialized = new SerializedObject(container);
 var items = serialized.FindProperty("Items");
 items.arraySize++;
 serialized.ApplyModifiedProperties();
 container.Items[container.Items.Length - 1] = containerItem;

Now I get "Save Changes?" window on shutdown. But then I though, meh, what the heck, and ended up with a single line:

 EditorApplication.SaveScene();
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

22 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

Related Questions

If I make changes to a prefab in the Project tab, do I have to save the scene, too? 1 Answer

Will Restoring my computer restore my scene? 0 Answers

Byte array of serialized data in MonoBehavior - changes not written to disk 1 Answer

Scene got cleared, but the file size is still 108kb 1 Answer

Get dirty state from a scene 3 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