• 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
Question by Bovine · Aug 13, 2011 at 08:43 PM · editorassetscriptableobjectdata

Are all ScriptableObject assets included in the build?

Hi There

I'm t$$anonymous$$nking of storing some editor data in some ScriptableObject assets but as t$$anonymous$$s data is not required by the game itself, will Unity know that t$$anonymous$$s asset isn't used. On the flip side, can I load an asset manually that DOES need including and will Unity know to include t$$anonymous$$s asset - would it need to be in the resources folder?

Thanks H

Comment
Statement
rakkarage

People who like this

2 Show 3
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 Bovine · Aug 14, 2011 at 08:05 AM 0
Share

If I use AssetDatabase.CreateAsset() in my EditorWindow to create an asset based on a ScriptableObject subclass I think I'll have no choice but to load it from the Resources directory in actual fact, so I think that, with the answers below answers my question!

avatar image Bunny83 · Aug 14, 2011 at 12:45 PM 1
Share

Well, your question is not that clear what assets you're talking about. The ScriptableObject classes are all included like i said in my answer. Serialized instances that are stored in .asset-files are something different. They behave like any other "data"-asset like NOAA_Julien explained.

The asset doesn't need to be stored in a Ressources folder, you can assign it to a reference variable of another script in the scene.

 public class MyDataObject : ScriptableObject  
 {  
     public string myString;  
 }  

 public class MyScript : MonoBehaviour  
 {  
     public MyDataObject myData;  
 }  

In this case when you drag&drop the serialized asset onto myData of an object in a scene the scriptable object instance is referenced and will be included.

avatar image Bovine · Aug 14, 2011 at 03:05 PM 0
Share

@Bunny83 sorry if the question wasn't clear. I want to have some Configuration Data for an Editor or EditorWindow - I have not yet decided which - that will persist from load to load and scene to scene, but I don't want to have this data in my game. My understanding is that if I subclass ScriptableObject I can then use an instance of that to create an asset from my Editor/EditorWindow and load it if it exists when the Editor appears.

The Editor/EditorWindow I create will generate assets itself, and I was thinking I'd have to load these manually, but of course - as you point out - I can dop them onto members of that type where I need to use them, which is MUCH nicer :)

Thanks.

4 Replies

· Add your reply
  • Sort: 
avatar image
Best Answer

Answer by Julien-Lynge · Aug 13, 2011 at 08:54 PM

If no scene objects reference a script, Unity is pretty good about cleaning those up when compiling - they won't be included in your game. If a gameObject or any script in a gameObject references an asset, it will be included in the game. The Resources folders are only for if you want to reference an asset with Resources.Load at runtime. If you're ever in doubt about whether a needed asset is there, just compile (it takes about 30 seconds) and run the game.

Comment
Statement
Bovine
Waz
JhonH3avy

People who like this

4 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 Waz · Aug 14, 2011 at 02:17 PM 1
Share

And to be clear, all Resource folder assets are included, regardless of reference.

avatar image Bovine · Aug 14, 2011 at 03:11 PM 0
Share

Sure, this was why I initially thought I'd need to store any asset created with AssetDatabase.CreateAsset() in the Resources folder, but as Bunny83 points out, the Asset can be dragged and dropped just like any other asset!

avatar image

Answer by Bunny83 · Aug 13, 2011 at 09:51 PM

In normal Unity builds (Standalone, Web) all (runtime) classes are included in the build. Unity compiles all scripts into a .NET / Mono DLL. There is a DLL for each compiling group (Standard Assets / editor / normal script) and for each language you're using. If you're mixing Unityscript and C# and have some scripts in Standard Assets and also some editor scripts written in C# and UnityScript you will end up with 6 DLL files. only 4 will go into the build since the editor DLLs only work in the editor.

 Assembly-CSharp-firstpass.dll
 Assembly-CSharp.dll
 Assembly-UnityScript-firstpass.dll
 Assembly-UnityScript.dll

You can find those dlls in the standalone build here : $ProjectName$_Data/Managed/

Unity have to include all scripts since you can use reflection or string based functions to access classes. Just t$$anonymous$$nk of Addcomponent("MyClass")

Mobile builds have the special option to strip unused code from the build but when you use reflection to access stripped classes it will crash. As far as i know the string based function calls will work as long as you call it with a string literal. It you build the string at runtime Unity can't detect that you use the class and would strip the class. That's why it's an optional feature in pro and "can" be enabled ;)

Maybe i'm wrong how the codestripping exactly works but i guess it works like that ;)

ps. in webbuild the dlls are wit$$anonymous$$n the compressed package. As far as i can remember someone managed to "decompress / disassemble" such a package, so your stuff is not "safe" especially the code.

Comment
Julien-Lynge
Bovine
Waz

People who like this

3 Show 7 · 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 Bunny83 · Aug 14, 2011 at 12:53 PM 0
Share

Just for the record:

To create an instance of a ScriptableObject at runtime you normally use:

 // C#  
 ScriptableObject.CreateInstance<MyScriptableObject>();  
   
 // or  
 ScriptableObject.CreateInstance("MyScriptableObject");  
   
 // or  
 ScriptableObject.CreateInstance(typeof(MyScriptableObject));  

This will create a new instance of that class similar to AddComponent() but since ScriptableObjects can't be attached to GameObjects you have to create it that way.

If you have a serialized instance (created in the editor, saved as asset) you would use Instantiate() to clone the initialized instance. If you use Instantiate on a MonoBehaviour the GameObject it's attached to is also cloned.

avatar image Bovine · Aug 14, 2011 at 03:09 PM 0
Share

Sure, but the assets used in my EditorWindow I imagine I'll be using AssetDatabase.LoadAssetAtPath(). Of course if there's a better place to store settings required by editor windows then please shout loudly! :)

avatar image Bunny83 · Aug 15, 2011 at 06:55 PM 0
Share

Well, it depends on what "settings" you want to store. If you have settings that are valid for your EditorWindow itself and not just for a specific instance you're editing with it, use EditorPrefs. But if you want to store data for a specific object in the scene or a prefab you have to use something like a ScriptableObject and store it as a seperate asset.

avatar image Bovine · Aug 15, 2011 at 08:50 PM 0
Share

@Bunny83 Sorry, I maybe should have put the use-case for this. For our RPG we are working on, many of the items follow a pattern which allows me to construct a range of items based on some predefined characteristics. We're doing it like this because we can then know the range of stat modifications up front for play balance and because there's only two of us and a modest item set generates around 3000 items, not countting specials or rares.

This means there are several structures we iterate over to build the real item data. This data doesn't need to be loaded in the game although I could generate the item data on game startup but I think that might cause problems for the quest system, so I want the data to persist in the editor so I can edit it and then recreate all the generated game items at the click of a button.

As of this evening I've been tinkering with an EditorWindow that loads or creates an asset from a ScriptableObject that contains the generation information. It seems to work fine - though I do wish the Editor GUi had a list control!!

I looked briefly at EditorPrefs but the data is limited so a ScriptableObject and EditorWindow is the direction I've gone with this. We did have the generation outside of Unity but I had to duplicate some structures and it was getting rather cumbersome to update - this will be much better!

avatar image Bovine · Aug 17, 2011 at 12:25 PM 0
Share

This is the EditorWindow I've ended up with...

http://www.bovine-software.co.uk/Images/item_generation_window.png

But it feels like a lot of work to get there!

Show more comments
avatar image

Answer by Statement · Aug 13, 2011 at 08:54 PM

If they are being referenced from the scenes or if they exist in Resources folder, then yes, I t$$anonymous$$nk so. Otherwise I am unsure. I wouldn't expect them to be included since they can't be used if they aren't referencable. I guess you could do a quick test project/scene and export the game without a scriptable object, then add a scriptable object and compare the exported games?

Comment
Bovine

People who like this

1 Show 0 · 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

Answer by tnetennba · Aug 15, 2011 at 07:49 PM

You can use t$$anonymous$$s script to see if any objects in your game actually use it and if not clear up your project.

http://forum.unity3d.com/threads/100399-How-can-I-find-what-objects-are-using-another-object

Be warned there is no progress bar on it yet so you just have to be patient and wait for it finish.

Comment

People who like this

0 Show 0 · 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.

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

9 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Problem with ScriptableObject and Custom Editor 2 Answers

Is there a message to be listen to when editor enter play mode? 2 Answers

How can I find all instances of a Scriptable Object in the Project (Editor) 3 Answers

[Solved]Why doesn't my ScriptableObject based asset save using a custom inspector ? 1 Answer

Save ScriptableObject On Unity Application Quit? 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