• 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 creay · Nov 30, 2016 at 10:56 AM · scripting problemassetsavescriptableobjectassetdatabase

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

Unity can create asset (ScriptableObject ) by using AssetDatabase.SaveAssets() at editor script .

Why unity can't create/save asset (ScriptableObject ) at runtime(means in a build) ?

Is there technical difficulties or it been designed this way ?

If it's designed this way , why ?

Comment
Add comment · Show 7
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 ThePersister · Nov 30, 2016 at 10:37 AM 2
Share

Hi there @creay,

That is the intended behaviour, you cannot permanently add scriptable objects, or save / serialize them.

Here's a question similar to yours: http://answers.unity3d.com/questions/874590/scriptable-objects-not-working-after-being-built.html

If you look at the answer of Bunny, he explains how "When you create a build of your project all assets are packed into packages which can't be modified at all." and "A build can only read the packed assets."

So yes, it was designed that way. Perhaps unity would've opted to allow for asset creation at runtime, but that's probably not possible due to build packaging shenanigans that are inaccessible from the build itself.

I hope that helps, if you need any more details, let me know! :) (Note, since this question is in moderation at this point in time, I chose to try to answer your question via comments)

avatar image creay · Dec 02, 2016 at 07:20 AM 0
Share

@ThePersister thanks for your answer, it's helpful.

Accroding to @Bunny83's answer "Only the Unity editor can actually serialize anything. Unity's serializer isn't available at runtime. A build can only read the packed assets."

It seems the deserializer is available at runtime but serializer isn't.

I still don't understand why it's designed this way, what's the benefit of it ,wouldn't it be better if deserializer and serializer both available at runtime ?

avatar image ThePersister creay · Dec 02, 2016 at 09:47 AM 0
Share

That does seem strange, I bet there are technical reasons for it.

For one, unity won't compile any build or serialization functionalities along with your game on its own, because that would explode the size of mobile builds!

Reasons like that.

Luckily, we can easily add our own serialization methods. One of which for example would be: http://answers.unity3d.com/questions/610893/how-do-i-save-a-custom-class-of-variables-to-playe.html

I'm currently working with scriptable objects as well. I plan to serialize the scriptable objects to binary data, and then simply save that binary data using for example the code in the link above.

There are several other ways to save data, this is just the way I'm headed. I hope that helps.

I suppose Unity designed it that way, so that it doesn't force functionalities, build size and other complexities upon you, but leaves it up to you to decide how you want to handle things!

I hope that satisfies your request. If you're interested in more details, you can always try mailing unity staff or checking out the "live training sessions" and asking it there.

Here's some unity Twitter accounts you can hunt down: Unity Twitter Accounts

Best of luck!

Cheers,

ThePersister

unitytwitter.png (431.6 kB)
avatar image creay ThePersister · Dec 02, 2016 at 09:56 AM 0
Share

Thanks....

Show more comments

0 Replies

· Add your reply
  • Sort: 

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.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

Custom assets give Missing (Mono Script) 0 Answers

How to change an object's name inside an asset file? 0 Answers

How to get enumerate all assets of a specific class? 3 Answers

Awarding 400 points if we solve this ---- AssetDatabase.LoadAsset("path") loads (null) instead of scriptable object (after enter/exit playmode) 1 Answer

.asset file containing ScriptableObject is empty on openingUnity 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