I’m thinking of storing some editor data in some ScriptableObject assets but as this data is not required by the game itself, will Unity know that this asset isn’t used. On the flip side, can I load an asset manually that DOES need including and will Unity know to include this asset - would it need to be in the resources folder?
Thanks
H
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!
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.
And to be clear, all Resource folder assets are included, regardless of reference.
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!
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.
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 think 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 within 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.
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! :)
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 <a href="http://unity3d.com/support/documentation/ScriptReference/EditorPrefs.html">EditorPrefs</a>. 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.
@Bunny83 thanks. I did wonder part way through whether I ought not just to have an editor for a my subclasses scriptable object buttons to create them and generate the 'real' data. Still it was a useful way to learn a little about editing, although I did find it wasn't entirely intuitive in terms of how I might do some simple things like add borders and change colours, but it is quite different to say a Windows or OSX framework.
If they are being referenced from the scenes or if they exist in Resources folder, then yes, I think 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?
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!
– Bovine