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 metroidsnes · Mar 19, 2015 at 07:05 AM · assetsavescriptableobject

ScriptableObject asset not saved to disk

I have this ScriptableObject class:

 public class ExampleScriptableObject : ScriptableObject {
 
         public string testName;
         public int value;
 }

which I instantiate with this code:

 [MenuItem("Assets/Test/ExampleScriptableObject")]
         public static void CreateExampleScriptableObject() {
             ScriptableObjectUtility.CreateAsset<ExampleScriptableObject>();
  }

and the access it from this MonoBehaviour:

 class ExampleMonoBehaviour : MonoBehaviour {

     public ExampleScriptableObject ExampleScriptableObject;
     public string TestName;
     public int Value;

     private void OnValidate() {
         ExampleScriptableObject.testName = TestName;
         ExampleScriptableObject.value = Value;
     }
 }

alt text

Each time I change value in the inspector and save scene/project, the change is only reflected in the scene file;

alt text

but asset file remains empty:

 %YAML 1.1
 %TAG !u! tag:unity3d.com,2011:
 --- !u!114 &11400000
 MonoBehaviour:
   m_ObjectHideFlags: 0
   m_PrefabParentObject: {fileID: 0}
   m_PrefabInternal: {fileID: 0}
   m_GameObject: {fileID: 0}
   m_Enabled: 1
   m_EditorHideFlags: 0
   m_Script: {fileID: 11500000, guid: 1929e198d1f69204cbed8c2482e19fe9, type: 3}
   m_Name: Test.ExampleScriptableObject
   m_EditorClassIdentifier: 

How can I save changes made to asset to disk instead of to the scene file?

examplemonobehaviour.png (7.5 kB)
scene-changes.png (10.7 kB)
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

3 Replies

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

Answer by metroidsnes · Mar 19, 2015 at 07:51 AM

Create custom inspector for the MonoBehaviour and in OnInspectorGUI() call EditorUtility.SetDirty() with the ScriptableObject asset passed as argument.

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
6

Answer by chakalaka · Mar 19, 2015 at 08:43 AM

call

 EditorUtility.SetDirty(ExampleScriptableObject);

to save your object

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 DSL-TailorIt · Jun 12, 2017 at 06:40 AM

Since this is the top Google result for this issue, I'd like to complement the previous answers by suggesting also taking a look at AssetDatabase.SaveAssets() which effectively saves the changes to disk.

Useful for automated tools and stuff.

Comment
Add comment · Show 2 · 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 wladyslaw · Aug 10, 2018 at 12:50 PM 1
Share

In my situation (a scriptable object is modified by an editor script) it didn't work all the time. I used SetDirty(myObject) ins$$anonymous$$d and it helped (the asset got updated in the editor and by saving the scene it was saved to disk) — but only after I commented out the line with AssetDatabase.SaveAssets()! So basically my problem was solved, but I would still like to see a solution which would automatically save changes to a ScriptableObject to disk whenever I want.

avatar image Zengon · Dec 13, 2019 at 04:02 AM 0
Share

You're a legend. This worked beautifully for me. All I was trying to do was set a single string password in my scriptable object but it was not saving to file, calling AssetDatabase.SaveAssets() fixed my issue.

Thank you!!

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

26 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

Related Questions

Saving a ScriptableObject .asset on Android? 1 Answer

Why unity can't create/save asset (ScriptableObject ) at runtime ? 1 Answer

Export Settings or custom files to release builds 1 Answer

Prefab as a subasset of a ScriptableObject 0 Answers

Why does my List overwrite itself when using .Add? 2 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