- Home /
How to persist design-time data (excluded from the final game)?
Hi,
I'm working on a component that needs to store a big amount of data that are not meant to be included in the final game. This database is used as inputs to generate assets at design time, and is Editor related only.
As far as I understand (very new to unity) ScriptableObject should be used for complex data structure in order to store instance references, with polymorphism support, which is exactly what I need. I've read also that serialized private fields are meant to be used from the Editor only.
And from this similar question, it seems that a #if UNITY_EDITOR preprocessor is available, which will be useful.
My question is the following: Is there any mechanism available to prevent data from being included in the final game?
The issue here is mostly about the size of the final package, with data useless at runtime
Answer by RudyTheDev · Nov 27, 2014 at 08:19 PM
Anything not referenced would not be included (with a few exceptions). You can make a ScriptableObject asset and store your data there. If Unity detects that your in-game objects never reference it, then it won't get included in the build. This is like dropping a huge texture into the project and never actually using it. It won't get included.
#if UNITY_EDITOR
would matter for scripts. All scripts (main exception being those in Editor\ folder) are included in the build. If you mark them for editor only, then that code won't be included. But you can still use it to manage your custom data assets at design-time.
See reducing file sizes to check how to know what's included in the build. See special folder names for how those affect inclusion.
Thank you so much for this clarification! This makes things all clear :)