Search Unity

Assets [RELEASED] ScriptableObject Databases

Discussion in 'Works In Progress - Archive' started by icepick912, Dec 31, 2018.

  1. icepick912

    icepick912

    Joined:
    Jul 8, 2010
    Posts:
    58
    ScriptableObject Database
    Asset Store Link: http://u3d.as/1t0f

    Easily create database for ScriptableObjects in only a few seconds. Organize your ScriptableObject data into database files for convenience. No coding required just use the Database Type Creator to quickly and easily set up a database for any ScriptableObject type. Use custom inspectors and property drawers? No problem, the Data displayed uses Unitys built in inspector and automatically uses any custom Inspectors and drawers you have set up for the data.

    Database Type Creator Features

    • Select where in the dependency chain to create a Database. The database will then be able to hold, and create all Types that inherit from that base type, ignoring abstract types.
    • Name the database type for use in file and class naming. e.g. 'ItemAssetDatabase'
    • Select locations for your Runtime, and Editor scripts that are created
    • Once new Database Type is created, the Asset Database Editor Window will pick it up immediately
    DatabaseTypeCreator.png

    Asset Database Editor Window Features

    • Switch between different Database Types
    • Enable/Disable different Types when many different Database Types clutter your view.
    • Select, Create, and Delete Databases and ScriptableObjects
    • Create any Sub classes of a ScriptableObjects Type with 2 button clicks.
    • Rearrange the order of assets in the list.
    • View and modify any Serializable data the ScriptableObjects contain right in the editor window.
    • Support for all custom inspectors and property drawers by default
    • Drag and drop compatible Objects into the asset list for quickly adding an existing Object
    • Import external objects into the database as a Copy, or keep the data external and store a reference
    • Duplicate Objects and add them to the database
    AssetDatabaseWindowPreview.png
    AssetDatabaseInspectorPreview.png
    Planned Features
    • Move an existing ScriptableObject into the database, and update all references in the project
    • Use Embedded Resources to store the template files inside dlls with
    ScriptableObject Asset Database was created to fill a need I have for origination, and efficient workflows. I wanted to be able to create simple databases that could store any type of Unity Object I could create, and be able to create them in less than 30 seconds, including recompile time. It was to be minimalist, with the least amount of clutter that could effectively accomplish those 2 goals.

    With that in mind I use no custom icon or texture data. The Code is compiled into 2 dlls, one for Runtime, and one for the Editor. It also includes 2 EditorDefaultResource files that are used as templates for the runtime, and editor classes. The resulting classes and files created from these templates use 44 lines of code for any database you wish to create.

    The base database classes are not just for ScriptableObjects, included is an example that overrides 2 methods in the Databases generic class to allow a Prefab Database. If you know how to code, creating databases for any type of project data you can imagine should be trivial when extending the base Database classes.
     
    Last edited: Mar 16, 2019
    DungDajHjep, Duffer123, eaque and 2 others like this.
  2. icepick912

    icepick912

    Joined:
    Jul 8, 2010
    Posts:
    58
    Duffer123 and zyzyx like this.
  3. Duffer123

    Duffer123

    Joined:
    May 24, 2015
    Posts:
    1,215
    @icepick912 ,

    Looks really interesting.

    Some questions (I probably repeat myself a bit...):-

    1) Presumably we code and create our own scriptableobjects in .cs and generate one of whatever type first with whatever public variables, methods etc within (and see below)?

    2) How easy is it then in runtime to access scriptableobjects and variables within that? What does this Asset bring to the party in that regard, in terms of accessing and/or instancing SOs and accessing their variables?

    3) I mean also, can you create a blank canvas ScriptableObject and set up the variables within that SO as well using this Asset? Or do you (as above) have to .cs script (hard code) your SOs and their variables? Just the variables? (I can see that you can edit the variables within SOs once created).

    4) Also wondering if you can allow 'auto-magically' for Prefab or other Objects in Databases without code changes in the Editor?

    5) Can you effect or set where the actual SO (or other) Assets are saved? Don't they need to be saved under the Resources folder within Assets to be usable/referenced in runtime?

    6) Does this Asset come with an example Project(s)? I think that I see that it does?
     
    Last edited: Mar 6, 2019
    icepick912 likes this.
  4. icepick912

    icepick912

    Joined:
    Jul 8, 2010
    Posts:
    58
    Hey @Duffer123, thank you for the input and great questions!

    #1 Correct as of now. I may put an option in that would scan for the classes themselves to create one from. But at the moment yes you need to create an instance of a SscriptableObject in the project view to create a database for.

    #2 The asset comes with a Main Database Collection ScriptableObject that you are prompted to create upon import, or when it cannot be found. Using this object allows you to retrieve any asset based on its 32 bit key, which contains both the databases key, and the assets key. All you need is the INT ID of the asset and you can get any ScriptableObject that is in a database at runtime.

    #3 If I understand correctly, This tool does not generate the class files of custom ScriptableObjects. The databases themselves are ScriptableObjects, which contain functions for accessing and storing other user made ScriptableObjects. They are not limited to ScriptableObjects, the example in the asset comes with a variation that stores prefabs. The base database classes included with the source can be used to create non unity object storage, for that of maybe just pure data, with no reference to a project file.

    #4 There is an example of a Prefab database included in the asset. These databases can contain references to any type of unity object in the project, using the prefab example as a template, one could create databases for other unity objects, like animations, materials, etc. but I'm not sure most of these could be made a child of ScriptableObject. Which may not be an inconvenience for a user.

    #5 You may have references to scriptable objects any where in the project, just drag them over the asset list section in the Editor window, and the database will store a reference to the SO. You may also "Import" the SO into the database, and the reference will update to the "Internal" SO, You may also "Export" an "Internal" SO to the project, although in this case the reference inside the database is still the Internal version, you would have to delete the internal one, then drag the external SO back into the asset list.
     
    Last edited: Mar 6, 2019
    Duffer123 likes this.
  5. Duffer123

    Duffer123

    Joined:
    May 24, 2015
    Posts:
    1,215
    @icepick912 ,

    Great - thank you for such a comprehensive response. I'm quite happy coding my own .cs scriptable object to then create the Assets that would go within this Database and I can well see how this could save masses of time. Frankly I am sick of custom coding 'create asset menu' for each SO and inherited SO... ;)
     
    icepick912 likes this.
  6. Andrew900460

    Andrew900460

    Joined:
    Aug 9, 2017
    Posts:
    39
    What I'm seeing in those screenshots looks really nice! I definitely think this is something I would get.

    Right now I'm using someone else's database called "Visual Item Database" for the game I'm making. It works for what I'm doing, but there are a bunch of things that are starting to annoy me about it.
    For one thing, the "ItemBase" class is not a ScriptableObject like yours appears to be, and recently I came across an issue where when I have a serialized ItemBase variable and I have classes that inherit ItemBase, there is data loss if the data is loaded in edit mode. I read that ScriptableObjects don't have this issue so that solves one of my problems.

    Along with many other issues with this other database, one aspect that I never liked was that creating different types of items meant using inheritance, where I would have prefered to use a "component based" way of creating item types. Which it appears yours does do from what I see. Where the different objects can be given different groups of asset data depending on what item you are creating. And since your database is more generalized to any type of information and not just items, this would work well for creating a database of crafting recipes, level gen biomes, etc.

    If this is the case that your database is rooted in a modular component system and it is more generalized for any data, then I would definitely consider switching to yours in the near future. Also, your database is much newer, and this other guy's database was made in a much older version of unity so it's probably using a lot of older practices anyway.

    EDIT: I'm gonna get the asset. I'm curious if it will work for my project and I want to see how much it will help me with all the different datatypes I will need to save. I still would like a response to some of my concerns if they were not already answered above.
     
    Last edited: Mar 13, 2019
    Duffer123 likes this.
  7. icepick912

    icepick912

    Joined:
    Jul 8, 2010
    Posts:
    58
    @Andrew900460 Thanks for the questions!

    On creating many different item types by using inheritance. That is how I create databases ScriptableObjects in the screen shots, with a base item, and then multiple types inheriting from that. One could take the prefab example, and extend it to represent all ScriptableObjects in a project, however that could mean a large list of different types one could create, perhaps leading to data that is hard to maintain. But if a user only uses a few different types, then it is feasible.

    If I understand correctly the part about being rooted in a modular component system, ScriptableObjects themselves can be thought of as a component with no transform, that exist on their own. In that sense a user can define how the ScriptableObjects reference and interact with each other to determine links between systems. In reference to data that exists within different ScriptableObjects that all seem to be items, for this I do use inheritance, Think of a base item class that has data for stack size, category. Then I make a new item that inherits from this and I add into that new ScriptableObject data that is specific to that item, such as a Fuel Item that contains data about the power output per unit of fuel.

    This system is set up to make it darn easy to create databases, and have a nice window on the side to edit, create, view, and otherwise manage the data inside a database. That can allow you to view loads of data quickly, and still use the inspector for the scene view. Make as many or as few number of databases you like.

    If you have already used the tool, any input would greatly be appreciated. Such as what was unclear or non-intuitive about the tools uses. I would love some feedback.
     
  8. Andrew900460

    Andrew900460

    Joined:
    Aug 9, 2017
    Posts:
    39
    @icepick912

    Yea when you explain it that way it makes me rethink my idea about modular components. I'm getting too wrapped up in unity's way of programming entities since they don't use inheritance, but instead, use modular components, which allows you to define what a "thing" is by what that thing "does" rather than "this is a thing and it can do this and all other things like it HAVE to do what it does", anyway, I digress. I've been using unity for a year now and I'm still getting used to how certain thing's work.

    In your "Planned Features", you said you would make it so database assets would have icons with them, in this other store asset I've used, they have it setup where there is a special property where you add a sprite and it updates the item icon. The only thing I didn't like about it was that if the image was much smaller than the png size, the icon would be very small. So making the icon preview larger would be nice. There are a couple of other things from the other store asset that I thought were nice but I can't think of them right now, it's late here where I am but If you want to get some ideas on polish for the UI or other things you should check out "Visual Item Database" if you haven't already and see what they did.

    Lastly, and personally, I will be using your asset in my game for various things like Items, Crafting Recipes, Entities, Biomes, etc. I figure you're probably curious how others will use your database. So that's how I'll be using it. I haven't gotten into the scripting part of your database so I might sound silly here, but I also need some way of getting items of the databases through integer ID's and through some sort of "name tag"

    but anyway,
    Thanks again!
     
  9. icepick912

    icepick912

    Joined:
    Jul 8, 2010
    Posts:
    58
    The MainDatabaseCollection handles these.

    Code (CSharp):
    1. /// <summary>
    2. /// A Scriptable object used to keep track of all the databases in the project.
    3. /// </summary>
    4. [System.Serializable]
    5. public class MainDatabaseCollection : ScriptableObject
    6. {
    7. /// <summary>
    8.     /// Retrieves a specific database.
    9.     /// </summary>
    10.     /// <param name="id16">Database 16 bit ID.</param>
    11.     /// <returns>Database or null if database does not exist.</returns>
    12.     public IDatabaseFile GetDatabase(short id16)
    13.     { }
    14.  
    15. /// <summary>
    16.     /// Gets an asset using the 32 bit ID
    17.     /// </summary>
    18.     /// <param name="key32">32 bit ID containing both database and asset IDs.</param>
    19.     /// <returns>The specified asset or null if none was found.</returns>
    20.     public DatabaseAsset GetAsset(int key32)
    21.     {}
    22. }
    The first uses a 16 bit database id, located in every database.
    The second uses and 32 bit asset key, which also contains the database key.

    Retrieved from

    Code (CSharp):
    1. public abstract class DatabaseAsset
    2. {
    3.         /// <summary>
    4.         /// The 16 bit database ID.
    5.         /// </summary>
    6.         public short DatabaseID16 { get { return pKey.DatabaseKey; } }
    7.  
    8.         /// <summary>
    9.         /// The 16 bit asset id.
    10.         /// </summary>
    11.         public short AssetKey16 { get { return (short)pKey.AssetKey; } }
    12.  
    13.         /// <summary>
    14.         /// The combined database and asset id wrapped into a 32 bit integer.
    15.         /// </summary>
    16.         public int ID32 { get { return pKey.Key32; } }
    17. }
    Get the DatabaseAsset from

    Code (CSharp):
    1.     /// <summary>
    2.     /// Base database data.
    3.     /// </summary>
    4.     [System.Serializable]
    5.     public abstract class Database
    6.     {
    7.         /// <summary>
    8.         /// Num of assets the database references.
    9.         /// </summary>
    10.         public int NumOfEntries { get { return mKeys.Count; } }
    11.  
    12.         /// <summary>
    13.         /// Gets an asset at a certain index.
    14.         /// </summary>
    15.         /// <param name="index">Index into asset list to look.</param>
    16.         /// <returns>Asset at the index.</returns>
    17.         abstract public DatabaseAsset GetAssetAtIndex(int index);
    18.  
    19.         /// <summary>
    20.         /// Get an asset with a certain 16 bit ID.
    21.         /// </summary>
    22.         /// <param name="assetKey16">16 bit asset ID.</param>
    23.         /// <returns>The asset matching the specified ID.</returns>
    24.         abstract public DatabaseAsset GetAsset(short assetKey16);
    25.     }
    All databases will have this data, allows for accessing data at runtime.
    As for tags, you could make a different database that contains the items you want under a certain Tag, and then just use the database as the tag list. The databases can reference ScriptableObjects in other databases, or in the project view as references.
     
    Last edited: Mar 14, 2019
  10. icepick912

    icepick912

    Joined:
    Jul 8, 2010
    Posts:
    58
    I see how it was done there. I do have a texture atlas implementation sitting in there, for now it just creates a little 4 pixel x 4 pixel image, and adds it to the atlas. The only problem i see in the Editor UIs' how i have them is that if there are a lot of items, there is slow down time from me drawing all the icons in the list. I just need a way to only render icons that are in the scrollview, and thus viewable by the user. That would save a lot of cpu time. Setting up a Simple texture selector would be simple to add custom icons to items. If you look in the inspector I also draw the little 4x4 pixel atlas textures in the preview there. To do i suppose
     
  11. icepick912

    icepick912

    Joined:
    Jul 8, 2010
    Posts:
    58
    Heres the look of the icons work.

    IconUpdate.png

    The Icon atlas can be accessed at runtime with.

    Code (CSharp):
    1. /// <summary>
    2.     /// Base database data.
    3.     /// </summary>
    4.     [System.Serializable]
    5.     public abstract class Database
    6.     {
    7.         /// <summary>
    8.         /// Holds Asset Icons.
    9.         /// </summary>
    10.         public IconAtlas IconAtlas { get; set; }
    11.  
    12.         /// <summary>
    13.         /// The Icon Atlas texture.
    14.         /// </summary>
    15.         public Texture2D IconTexture { get; set; }
    16.     }
    17.  
    18.     public class IconAtlas
    19.     {
    20.         /// <summary>
    21.         /// Get the Rect region of the texture that contains the input ID.
    22.         /// </summary>
    23.         /// <param name="key16">The ID of the icon rect to retrieve.</param>
    24.         /// <returns></returns>
    25.         public Rect this[int key16]
    26.         {}
    27. }
    28.  
    This allows a user to get the Atlas texture, along with any assets Uvs for the icon in the texture atlas. As of now i think i have the atlas set to a max of 1024x1024 pixels, however any icons inserted into the database will be resized if they are too large.
     
    Last edited: Mar 14, 2019
  12. Andrew900460

    Andrew900460

    Joined:
    Aug 9, 2017
    Posts:
    39
    Thanks for the info!

    I hate to keep throwing questions here, but still can't figure out how you got the "title bars" in your Asset Data window. I feel like you might have explained it but I can't seem to get it working.

    I made a couple of S.O. one which is a base and the other inherits from the other and I setup a database for it, but it doesn't show any title bars like you have in your screenshots. Where you have "Description", "Base Data", "Icon Data With Layout". I have a feeling that is just a type of attribute I've never heard of, but this is the only place I've seen these before.
     
  13. icepick912

    icepick912

    Joined:
    Jul 8, 2010
    Posts:
    58
    That is a custom Unity inspector for the data I use, any custom inspector data will show exactly as they are shown in the default unity inspector. Sorry to mislead you with the screen shots. You could create Attributes to accomplish this if you want to say have simple headers with that kind of look, I do it through a custom inspector though.
     
  14. Andrew900460

    Andrew900460

    Joined:
    Aug 9, 2017
    Posts:
    39
    Do you have a discord server? There is probably a bunch of questions I have about your asset. I am really enjoying using it BTW.

    I notice that the Asset and Database ID's are random. I'm assuming you have a way of making sure you don't have any "collisions" with ID's and probing if it happens?
     
  15. justtime

    justtime

    Joined:
    Oct 6, 2013
    Posts:
    424
    Hi there! My SO has a lot of records, around 1k with 10 fields each one. It's very slow in Editor, will it be more optimized in your asset?
     
  16. icepick912

    icepick912

    Joined:
    Jul 8, 2010
    Posts:
    58
    Yep there's a database asset post processor in there that compares the created, and or imported database, and makes sure each has a unique id, and updates the conflicting databases id, and its assets 32 bit its, although the 16 bit ids can stay the same, only the database id needs to be updated.

    If I understand correctly, You mean you have 1k ScriptableObjects to go into the database? If that's the case, It may be pretty slow and cumbersome to have that many entries to have per database. I would recommend splitting the database up into smaller parts. What kind of data is it?

    If you mean the asset data that is displayed, It simply uses unity default inspector to render data for assets in databases. So there would be no difference.

    If you give me an example of the type of data that is stored i could offer a solution that may fit. But its very dependent on what kind of data it is.
     
    Last edited: Mar 15, 2019
    justtime and Duffer123 like this.
  17. icepick912

    icepick912

    Joined:
    Jul 8, 2010
    Posts:
    58
    Hrm i just noticed that's not in the build online, ill have to fix that. Thanks for pointing that out. Ill make it display a popup window to make sure the user knows a conflict existed, and let them know what 2 databases were affected. That way the user can make steps to fix the conflict.

    While this should be very rare, the chances are 1 in 32,767, and that only when importing databases. Not creating them.

    Conflicts should only be possible when importing a database from a unitypackage or another project. All links to the ScriptableObjects should remain intact should a conflict arise. The only type of data that may be affected is if you store references to the importing databases assets as simple ids. This also only pertains to data being imported that references the importing database. Think a list items that are only referenced by there ids, and not the ScripableObjects they represent. This would almost certainly negate a lot of the benefits of using ScriptableObjects, simple because you can refer to them as their objects and have all serialized data stay in tact. You can even edit the data inside ScriptableObjects and it will save the data in edit mode automatically.

    I see this becoming an issue if one has saved data to a disc and represented that data in a file as pure ids, In such a case it means the user would have to be responsible for updating the data in the save file to reflect the new values. You may inject your own code in the DatabaseManager.cs DatabasePostProcessor.

    Edit: Got the features in, will update with them plus the icon features.
     
    Last edited: Mar 15, 2019
  18. Duusty

    Duusty

    Joined:
    May 14, 2013
    Posts:
    56
    Does this asset has a field/picker (editor attribute) to easily select Id's of the database as references (maybe even with an inline editor for the inspector)

    Something like a DatabaseReference<Item> Object which i can for example add to my inventory class and then visually select the object in the editor, internally it serializes the ID and at runtime i can just access the data by something like DatabaseReference<Item>.Object ?
     
  19. icepick912

    icepick912

    Joined:
    Jul 8, 2010
    Posts:
    58
    I can definitely put that in. Would just be a custom drawer for the DatabaseAsset class, since the DatabaseAsset class contains both the database id and its own id, along with the ScriptableObject reference. I would just make a custom Drawer for that class, and the user would select which to use. Alternately I could make an attribute to use with a 32 bit int. and Simple use the attribute drawer to select and reference the asset and the database. Both options would allow the user to have a list of objects sorted by the database they reside in. I definitely see the workflow benefits of using something like this. Great suggestion. Thank you. Getting right on that
     
    Last edited: Apr 1, 2019
  20. icepick912

    icepick912

    Joined:
    Jul 8, 2010
    Posts:
    58
    Heres a look for it. The icons beside the databases, and assets allow a user to open a new inspector showing the object.

    AttributeUpdate.png

    A pic of the selection window that pops up when selecting a database or asset.

    AttributeUpdateB.png

    And heres the code and how to use.

    Code (CSharp):
    1. [System.Serializable]
    2. public class CustomEdtiorTest : MonoBehaviour
    3. {
    4.     public float oneOne;
    5.     [DatabaseAssetProperty(typeof(ItemDatabaseFile))]
    6.     public int[] MiscItemAssets;
    7.  
    8.     public bool toggler;
    9.     public string tester;
    10.     [DatabaseAssetProperty(typeof(PrefabDatabaseFile))]
    11.     public int PrefabAssets;
    12.  
    13.     [DatabaseAssetProperty(typeof(ItemDatabaseFile))]
    14.     public int ItemAsset0;
    15.  
    16.     public int flyer;
    17.  
    18.     [DatabaseAssetProperty(typeof(ItemDatabaseFile))]
    19.     public int ItemAsset1;
    20.  
    21.     public void Start()
    22.     {
    23.         Debug.Log("Asset 0:" + MainDatabaseCollection.GetAsset(MiscItemAssets[0]).name);
    24.         Debug.Log("Asset 1:" + MainDatabaseCollection.GetAsset(PrefabAssets).name);
    25.         Debug.Log("Asset 2:" + MainDatabaseCollection.GetAsset(ItemAsset0).name);
    26.         Debug.Log("Asset 3:" + MainDatabaseCollection.GetAsset(ItemAsset1).name);
    27.     }
    28. }
    By using the [DatabaseAssetProperty(typeof("DATABASETYPE"))] Attribute we can call only the databases of the desired type.
     
    Last edited: Apr 2, 2019
  21. Andrew900460

    Andrew900460

    Joined:
    Aug 9, 2017
    Posts:
    39
    testing your update in an empty project and I'm getting a bunch of weird errors
    Assets\Plugins\ScriptableObjectDatabase\Scripts\BlockTypeInspector.cs(24,27): error CS1031: Type expected
    Assets\Plugins\ScriptableObjectDatabase\Scripts\BlockTypeInspector.cs(24,27): error CS1026: ) expected
    Assets\Plugins\ScriptableObjectDatabase\Scripts\BlockTypeInspector.cs(24,27): error CS1002: ; expected
    Assets\Plugins\ScriptableObjectDatabase\Scripts\BlockTypeInspector.cs(24,27): error CS1012: Too many characters in character literal

    I think it has something to do with your template txt file not initializing properly. I have a feeling its just my end and I just missed something, but idk...

    EDIT:
    In the auto generated scripts for the databases the "XXXEditorGUI" class has a "typeof('parentsType')" function and if I leave the parent as null when creating the database then that gets set to null and it gives an error.

    EDIT2:
    As a temporary solution, I changed "typeof('parentsType')" to "null" because the database doesn't have a 'parent'.
     
    Last edited: Apr 13, 2019
    icepick912 likes this.
  22. icepick912

    icepick912

    Joined:
    Jul 8, 2010
    Posts:
    58
    Hrm yep yep, thanks for the info sir thats definately the problemo. Ill fix it up and resubmit.
     
  23. Andrew900460

    Andrew900460

    Joined:
    Aug 9, 2017
    Posts:
    39
    also, quick question, why is there a 32bit int ID in the asset selector on the left of window, and a 16bit int "asset ID" in the asset preview window?

    I'm guessing that's probably a combination of the 16bit database ID and the 16bit asset id?
    And thanks for the quick response. I like what you've done in this update.

    EDIT:
    And another quick suggestion. If you already have a lot on your plate don't fuss about it, but you should make it so if you "duplicate" an asset that the selected icon also gets copied with it. Currently, it doesn't and I would have to manually set it. Again, not a big deal. More of a 'quality of life' change.
     
    icepick912 likes this.
  24. icepick912

    icepick912

    Joined:
    Jul 8, 2010
    Posts:
    58
    Yep, the id containts both the database and asset ids both if which are 16 bit shorts, and thanks for the encouragement, it is much appreciated.
     
  25. icepick912

    icepick912

    Joined:
    Jul 8, 2010
    Posts:
    58
    @Andrew900460

    Submitted fix, and added the attributes to the new version, thanks for the input and helping find that bug!
     
  26. icepick912

    icepick912

    Joined:
    Jul 8, 2010
    Posts:
    58
    Tehe sorry saw that after submission, ill get it in the next one for sure :)
     
  27. chrisk

    chrisk

    Joined:
    Jan 23, 2009
    Posts:
    704
    This is an interesting asset and I have a question. I currently have many ScriptableObjects which I store many game-related parameters. A problem is that I have an external partner who likes to test the build with different parameters and can't give the whole editor. It would be really useful if you can modify the database at runtime. Is this possible? Thanks.
     
  28. icepick912

    icepick912

    Joined:
    Jul 8, 2010
    Posts:
    58
    By modify the database at runtime, you mean add and remove ScriptableObjects from the database? Or modify the ScriptableObject data the databases refer to. Both are possible by grabbing references to them using the MainDatabaseCollection Class.

    Use these methods to grab an instance of a database, or asset using ids.

    Code (CSharp):
    1. public class MainDatabaseCollection : ScriptableObject
    2. {
    3.     /// <summary>
    4.     /// Retrieves a specific database.
    5.     /// </summary>
    6.     /// <param name="id16">Database 16 bit ID.</param>
    7.     /// <returns>Database or null if database does not exist.</returns>
    8.     public static IDatabaseFile GetDatabase(short id16)
    9.     { }
    10.  
    11.  
    12.     /// <summary>
    13.     /// Gets an asset using the 32 bit ID
    14.     /// </summary>
    15.     /// <param name="key32">32 bit ID containing both database and asset IDs.</param>
    16.     /// <returns>The specified asset or null if none was found.</returns>
    17.     public static DatabaseAsset GetAsset(int key32)
    18.     { }
    19. }
    When you have references to the database you may use these functions from it.

    Code (CSharp):
    1. /// <summary>
    2.     /// Interface used with Scriptable Object to define a database
    3.     /// </summary>
    4.     public interface IDatabaseFile
    5.     {
    6.         /// <summary>
    7.         /// The ScriptableObject for the database.
    8.         /// </summary>
    9.         ScriptableObject File { get; }
    10.  
    11.         /// <summary>
    12.         /// Holds the asset data of the database.
    13.         /// </summary>
    14.         Database DatabaseData { get; }
    15. }
    From Here you May Access the DatabaseData field to gain access to the actual database. You may modify this in many ways using the functions inside.

    For the ScriptableObjects once you have the DatabaseAsset you may the following to get a reference to the UnityObject the asset is storing.

    Code (CSharp):
    1. [Serializable]
    2.     public abstract class DatabaseAsset
    3.     {
    4.         /// <summary>
    5.         /// Returns the UnityObject the asset references.
    6.         /// </summary>
    7.         public abstract UnityObject AssetObject { get; }
    8.     }
    From there you may modify any parts of the data the UnityObject holds, this is the ScriptableObject data that is stored in the asset. I Use UnityObject so the databases may store any type of UnityObject, not just ScriptableObjects, there is an example prefab database with the asset as well.

    If this isn't the answer you were expecting perhaps I misunderstood
     
  29. Duffer123

    Duffer123

    Joined:
    May 24, 2015
    Posts:
    1,215
    @icepick912 ,

    Unity 2019.1 throwing errors with this Asset. GUI related I am think. Check it.
     
  30. icepick912

    icepick912

    Joined:
    Jul 8, 2010
    Posts:
    58
    Im all over it :)
     
    Duffer123 likes this.
  31. icepick912

    icepick912

    Joined:
    Jul 8, 2010
    Posts:
    58
    Remove the Define Constraint "Unity_2018_3" on ScriptableObjectDatabaseEditor.dll import settings in the mean time.

    Info_0.png

    Info_1.png
     
    Duffer123 likes this.
  32. chrisk

    chrisk

    Joined:
    Jan 23, 2009
    Posts:
    704
    Hi, @icepick912, I'm talking about modifying the database data on a Built-Client, outside of the Editor.
    I guess there is no easy way to edit the ScriptableObject directly without using the editor and I was hoping it can read/write to json and I can then use external json editor.
    To me, database is not a database if the data cannot change on a built-client.
    I hope it sense. Thanks.
     
  33. icepick912

    icepick912

    Joined:
    Jul 8, 2010
    Posts:
    58
    I see. One would have to write custom serialize and deserialize code within scriptable objects to save and load the data with a byte file or json file. Its doable but not without a decent amount of work.

    I do see the value in such a feature, however that is beyond the scope of the plugin at the moment. Maybe a later update for integration with json exporting and importing. Would require a bit of reflection to automate such a feature however. And im always squeamish about using reflection.

    Thanks for the input and the idea for a future feature cheers.
     
    Duffer123 likes this.
  34. chrisk

    chrisk

    Joined:
    Jan 23, 2009
    Posts:
    704
    Hi, I just bought the asset and after the installation, it adds about a minute longer to start the Editor.
    I have large size project with many folders and I guess it's trying to scan the whole project.
    What's going on? I had to remove it from the project for now.
    Thanks for the help.
     
  35. icepick912

    icepick912

    Joined:
    Jul 8, 2010
    Posts:
    58
    It does scan for a file. I can move the file to a designated folder and autoload it instead of searching for it. So i believe you are correct. When i get home tonight ill get a fix for ya, what unity version do you use? And thank you for the feedback!
     
  36. chrisk

    chrisk

    Joined:
    Jan 23, 2009
    Posts:
    704
    Thanks for the quick reply.
    I'm using 2019.1.
     
  37. Andrew900460

    Andrew900460

    Joined:
    Aug 9, 2017
    Posts:
    39
    I have finally gotten back to my project, and I updated the database asset. If I remember correctly, in the 'asset list' for each item, it would show an asset ID, I'm gonna guess and say that it got moved to the 'selected asset viewer'. But I did like being able to see the ID's next to each item in the list. But I can see why you would remove it to compact things maybe.

    Or are we using the LIST NUMBER now to refer to an item? like #1 #2 #3 in the list?

    Idk if you did a video tutorial series yet, but that would be cool.
     
  38. icepick912

    icepick912

    Joined:
    Jul 8, 2010
    Posts:
    58
    I should have done a video tutorial to start, however i Didn't want it to be outdated too quickly. It still uses ids and not list indices, as doing it this way makes it easier to keep track of the objects, also makes the id static and unchanging so a user can be sure that if they are using ids to reference items they do not change.. As for the id info, window space is definitely at a premium, so I am trying to reduce the clutter in the UI, I will make a settings menu to where a user can customize how the user interface is displayed soon, also making the Object list slidable as seeing the names of Objects in the list can be a challenge with larger file names. Thanks for the input, and continuing support mate!
     
  39. Andrew900460

    Andrew900460

    Joined:
    Aug 9, 2017
    Posts:
    39
    I see what you mean with the video stuff.

    I'm starting to figure out how to use your database a little more, and I figured out I can get item id's in the inspector using the "DatabaseAssetProperty" attribute. I was also trying to figure out if there were other attributes to retrieve the actual S.O. reference rather than just getting its integer ID. So I wouldn't have to do the whole "((ItemDatabaseAsset)MainDatabaseCollection.GetAsset(id)).Asset;" to get the reference.

    As a suggestion, because this would actually be REALLY useful. If you made a Google word doc where you could just dump all the useful code examples that are possible. And pictures showing how to set up certain things. I know you have the Manual.pdf file, but that only gets updated when my asset gets updated, this way you can make changes whenever or have multiple Google docs for different versions.

    Also, from reading some of the other posts above ^, it sounds like there is a way to make a database that uses 32bit asset id's? Don't know if that's true or not, but sounds interesting. For my game, I have a block database and item database, but I don't need multiple databases for those data types. So idk if there is a way where that can be done where you have a database type where you can only have 1 database instance, but the asset id's can now be 32bit instead of 16.

    Lastly, I noticed that the item icon preview blurs smaller images, as they are getting upscaled. If there is a setting to make it upscale in nearest-neighbor so there is no blurring, that would be cool.

    Anyway, I still enjoy using this database. Keep up the good work!
     
  40. icepick912

    icepick912

    Joined:
    Jul 8, 2010
    Posts:
    58
    @Andrew900460

    I like the google docs suggestion, I will look into making it to where you can use 32 bit ids, and I will fix the icon blurring, thanks mate!
     
  41. Exonto

    Exonto

    Joined:
    Nov 22, 2017
    Posts:
    16
    Hi Icepick,

    Recently picked up your asset and I'm figuring out how to use it one step at a time. I think I understand how the databases work (for the most part), but how are prefab databases created? I can only seem to make SO databases and the examples don't seem to reveal how the prefab database was generated.

    Thank you.
     
  42. icepick912

    icepick912

    Joined:
    Jul 8, 2010
    Posts:
    58
    That one is a custom editor located at 'Assets\Plugins\ScriptableObjectDatabase\Examples\Scripts\Editor\PrefabDatabaseInspector' for the editor, and 'Assets\Plugins\ScriptableObjectDatabase\Examples\Scripts\PrefabDatabaseFile" for the ScriptableObject, i wrote it as an example on how to make databases for custom types.. Sorry for the confusions, i need to do better with documentation, and make a video for the plugin. Cheers!
     
  43. icepick912

    icepick912

    Joined:
    Jul 8, 2010
    Posts:
    58
    1.3 Submitted for approval, should be up in a day or two.

    1.3 :
    -Added support for Unity version 2019
    -Changed way the MainDatabaseCollection is handled, making it faster to load for larger projects
    -Added a drag control to expand the Asset List so users can see longer Object names
    -Added Menu Option "Window/ScriptableObject Database/Scan for databases" to scan for all databases in a project if some are missing.
    -Rearranged the UI a bit, and added option to disable list numbers in Asset List.
     
  44. Exonto

    Exonto

    Joined:
    Nov 22, 2017
    Posts:
    16
    Is there a way to get the ID16 of a database without having to debug? I found where you show asset ids but haven't been able to find the equivalent for databases.

    Thanks
     
  45. icepick912

    icepick912

    Joined:
    Jul 8, 2010
    Posts:
    58
    Nope actually, ill put it in the database details section most likely, ill send ya a link with the new version and put that in as well. Thanks for the input @Exonto!
     
    Exonto likes this.
  46. Andrew900460

    Andrew900460

    Joined:
    Aug 9, 2017
    Posts:
    39
    I don't think I updated to 1.3 yet, but I discovered that the database doesn't work if I build the project as an exe. It works in the editor, just not standalone.

    Here the error that pops up:
    NullReferenceException: Object reference not set to an instance of an object
    at MainDatabaseCollection.GetAsset (System.Int32 key32) [0x0000a] in D:\Unity\_VsProjects\ScriptableObjectDatabaseRuntime\ScriptableObjectDatabaseRuntime\Scripts\MainDatabaseCollection.cs:50
    at ChunkManager.loadChunk (UnityEngine.Vector2Int chunkPos) [0x00093] in C:\Users\Andre\Documents\Unity Projects\Below The Stone\Assets\Below The Stone\Scripts\Level\LevelManger\ChunkManager.cs:76
    at ChunkManager.loadChunksFromQueue (System.Int32 count) [0x00041] in C:\Users\Andre\Documents\Unity Projects\Below The Stone\Assets\Below The Stone\Scripts\Level\LevelManger\ChunkManager.cs:104
    at ChunkManager.UpdateChunks () [0x0005e] in C:\Users\Andre\Documents\Unity Projects\Below The Stone\Assets\Below The Stone\Scripts\Level\LevelManger\ChunkManager.cs:43
    at LevelManager.Update () [0x00001] in C:\Users\Andre\Documents\Unity Projects\Below The Stone\Assets\Below The Stone\Scripts\Level\LevelManger\LevelManager.cs:32

    (Filename: D:/Unity/_VsProjects/ScriptableObjectDatabaseRuntime/ScriptableObjectDatabaseRuntime/Scripts/MainDatabaseCollection.cs Line: 50)


    not sure what's going on since it's calling a static function. Or if something with my code...
     
  47. icepick912

    icepick912

    Joined:
    Jul 8, 2010
    Posts:
    58
    I fixed this is the new version, but the dll thats located at Assets/Plugins/ScriptableObjectDatabase/Compiled/ScriptableObjectDatabaseRuntime, must be set to any platform, instead of editor only as seen here.

    Location:


    Image0.png

    Change From This:

    Image1.png

    To This:

    Image2.png

    Let me know if that's the problem please sir.
     
  48. Andrew900460

    Andrew900460

    Joined:
    Aug 9, 2017
    Posts:
    39
    I updated the plugin, and all those platforms settings were the way they should be. I rebuilt my project, and it still gave the same error in the standalone. I will triple check but I'm sure the dll platforms are correct.

    I looked into it a little more, and it happens when I do:
    MainDatabaseCollection.GetAsset(validAssetId);
    and the error says: "NullReferenceException: Object reference not set to an instance of an object"
    Something at line 50 in your MainDatabaseCollection.cs file is null, but only when the game is ran as a standalone.

    Like I mentioned above,

    Do I have to have some sort of gameobject with a monobehaviour in the scene to fix this?

    It's weird because in the editor everything is fine, but as a standalone exe it causes an error.
     
    Last edited: Jun 21, 2019
  49. Andrew900460

    Andrew900460

    Joined:
    Aug 9, 2017
    Posts:
    39
    update on the post above ^

    I did some more troubleshooting, and it seems I have found what is causing this odd issue.
    All I had to do is create a Mono script that had a reference to the MainAssetDatabase:
    using UnityEngine;

    public class DatabaseLoader : MonoBehaviour {
    public MainDatabaseCollection database;
    }


    NOTE: I am not accessing this class from anywhere, it does absolutely nothing, but it fixes the standalone bug.

    for whatever reason, doing this must make some variable in your MainAssetDatabase class non-null or visible when I call Its static functions. I don't know what variable that might be, since I can't see the source code, and the source zip file you provided must be older code because the errors never lined up with the source code.

    I'm not sure if there is anything on your end that you could do for a future update so I won't have to include this tiny script in my scene. It's not gonna cause issues or anything, but considering you're trying to go for a pure static access to the database without needing singletons or variable references, this might be something worth looking into.

    For now, this is a fair workaround, but it would be cool if I didn't have to include this extra script.
    But this isn't a high priority by any means, so take your time, and focus on whatever else you're in the middle of.
     
  50. icepick912

    icepick912

    Joined:
    Jul 8, 2010
    Posts:
    58
    Yeppers was accessing the mainDatabaseCollection Asset incorrectly, got it fixed and tested on 2018.3, thank you for the input sir!, I'll send you the updated runtime dll. and update the asset in the store. Thanks Andrew!