Search Unity

  1. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

BG Database (inMemory database | Excel/Google Sheets syncing | CodeGen | Save/Load support)

Discussion in 'Assets and Asset Store' started by BansheeGz, May 3, 2018.

  1. BansheeGz

    BansheeGz

    Joined:
    Dec 17, 2016
    Posts:
    364
    Thank you for the update!

    A small comment:
    If you want to find the first row (or all the rows) meeting some criteria, you can also use FindEntity/FindEntities methods
    For example, let's say you want to find the first row/all rows with StockQty > 10
    Code (CSharp):
    1.         //find the first row with StockQty > 10
    2.         var entity = DatabaseDump.FindEntity(dump => dump.StockQty > 10);
    3.         print(entity == null ? "No row found" : "A row is found " + entity);
    4.  
    5.         //find all rows with StockQty > 10
    6.         var entityList = DatabaseDump.FindEntities(dump => dump.StockQty > 10);
    7.         print($"Found {entityList.Count} rows");
    8.  
    The advantage of these methods is that you can use any condition without any additional setup.
    You can replace dump.StockQty > 10 condition with any condition.
    The disadvantage of these methods is that they are slow with O(n) efficiency (n is a rows count) because they iterate the rows one by one.
    Using keys or indexes provides a faster alternative for searching the row(s), more details https://www.bansheegz.com/BGDatabase/Misc/KeysAndIndexes/
     
    zKici likes this.
  2. thatscraigz

    thatscraigz

    Joined:
    Mar 27, 2015
    Posts:
    100
    Hello again! :)

    I had a quality of life request or perhaps question - when generating playmaker actions, the 'set data' portion of actions defaults to a null/empty input variable. Would it be possible have it default to the fsm default datatype instead? I find I often will forget to set one of these actions variables to none and overwrite the runtime value on accident ><

    here is reference of an action regenerated with a new parameter and its default of 0 and others manually set to none early, as well as the default action null values.

    I hope you are doing well, thank you again for making this tool! :D
     

    Attached Files:

    BansheeGz likes this.
  3. BansheeGz

    BansheeGz

    Joined:
    Dec 17, 2016
    Posts:
    364
    Hello,
    Thank you for bringing this to my attention!
    I DMed updated packages to you, if something does not work as expected, please, let me know
     
  4. zKici

    zKici

    Joined:
    Feb 12, 2014
    Posts:
    438
    What am i doing wrong?

    BGRepo.I.Addons.Get<BGAddonLiveUpdate>().Load(true);

    Gives me this:

    WebException: The remote server returned an error: (400) Bad Request.
    System.Net.HttpWebRequest.GetResponseFromData (System.Net.WebResponseStream stream...

    and

    BGException: Error while loading meta 'DatabaseDump': The remote server returned an error: (400) Bad Request.
    UnityEngine.Debug:LogException(Exception)
    BansheeGz.BGDatabase.BGLiveUpdateDataSourceA:Error(BGMergeSettingsEntity, BGMetaEntity, String)

    but also:

    BGDatabase.LiveUpdate plugin log: Status: LoadAttempted, Ok meta count: 0, Invalid meta count: 1, Ok cells count: 0, Invalid cells count: 0


    works without a problem with export/import option in editor, just runtime is not ok?
     
  5. zKici

    zKici

    Joined:
    Feb 12, 2014
    Posts:
    438
    Additional question,

    Can I go through each Entity only if its of the same SymbolKey (i already set it up as key in config)

    So i can calculate totals for each entity individually, because seems like using DatabaseDump.GetEntityByKeySymbolKey(Symbol).CostAmount
    Gives the wrong totals so I'd rather manually calculate each one,

    Thanks
     
  6. zKici

    zKici

    Joined:
    Feb 12, 2014
    Posts:
    438
    Is there a way that I can post/paste the XML data into Google Sheets via bgdb?

    I'm parsing a lot of data from csv and would like to paste the xml automatically into the db and update google sheets, or will it have to be manual?
     
  7. BansheeGz

    BansheeGz

    Joined:
    Dec 17, 2016
    Posts:
    364
    Do you use GoogleSheetsAPI with API key?
    53.png
    If yes, maybe your API key is invalid?
    Here is how a valid API key looks like (this API key does not work actually, it's just an example)
    AIzaSyBzabUwpLveNcqmsDA-QEIDiDtqYSm2U74

    I would not recommend to use GoogleSheets API with API key in releases, cause API key is exposed in this case
    I'd switch to Visualization API instead (only "spreadsheet ID" parameter is required)
    Check if your "spreadsheet ID" is set up properly
    Use the following URL as a template
    https://docs.google.com/spreadsheets/d/[YourSpreadsheetID]/gviz/tq?tqx=out:csv&sheet=DatabaseDump
    Replace [YourSpreadsheetID] parameter with your actual spreadsheet ID and use this URL in your browser
    If everything is set up properly, "data.csv" file should be downloaded with your DatabaseDump sheet data.
    54.png

    DatabaseDump.GetEntityByKeySymbolKey should return a first row with provided Symbol value and DatabaseDump.GetEntityByKeySymbolKey(Symbol).CostAmount should return CostAmount field value of the first row with provided Symbol value, for example
    55.png
    "Test2" row is the first row with Symbol=2, so its "CostAmount" value (14) is printed to Unity console

    If you want to calculate a sum of "CostAmount" values of all rows with Symbol=2, you can use
    DatabaseDump.GetEntitiesByKeySymbolKey method, which should return all rows with provided Symbol value, after that you can iterate over these rows and calculate the sum (or something else)
    56.png

    Code (CSharp):
    1.         // the list of all rows with Symbol=2
    2.         List<DatabaseDump> rows = DatabaseDump.GetEntitiesByKeySymbolKey("2");
    3.         var sum = 0;
    4.         //iterate over the rows and calculate the sum
    5.         foreach (var row in rows) sum += row.CostAmount;
    6.         print(sum);

    Alternative method using LINQ
    Code (CSharp):
    1.         var sum = DatabaseDump.GetEntitiesByKeySymbolKey("2").Sum(dump => dump.CostAmount);
    2.         print(sum);

    Alternative method without using the key (a slower one)
    Code (CSharp):
    1.  
    2. var sum = DatabaseDump.FindEntities(dump => dump.Symbol == "2").Sum(dump => dump.CostAmount);
    3. print(sum);
    4.  

    Also, keep in mind, you can always simply iterate all rows one by one (if it makes sense), for example
    Code (CSharp):
    1.  
    2. var sum = 0;
    3. var count = DatabaseDump.CountEntities;
    4. for (var i = 0; i < count; i++)
    5. {
    6.     DatabaseDump dump = DatabaseDump.GetEntity(i);
    7.     if (dump.Symbol != "2") continue;
    8.     sum += dump.CostAmount;
    9. }
    10. print(sum);
    11.  

    Regarding CSV
    We could add support for CSV files import/export if it can help

    Regarding XML
    Most probably the simplest way is to parse your XML files, add/update database records, and then push this data to Google Sheets
    Even if we add support for XML import/export (it's probably a trivial task) we would use our own XML file format and there is a tiny chance it will be the same as your XML files format, so probably you won't be able to employ this feature anyway
    It's possible to create another XML file, describing original XML content and mapping XML attributes/elements to database tables/fields, not sure how simple it will be
    We could implement this feature if it can help

    Please, let me know if you have any question
     
    Last edited: Jul 25, 2023
  8. zKici

    zKici

    Joined:
    Feb 12, 2014
    Posts:
    438
    Okay I tried with Visualization API only, however when i get :
    BGDatabase.LiveUpdate plugin log: Status: LoadAttempted, Ok meta count: 0, Invalid meta count: 0, Ok cells count: 0, Invalid cells count: 0

    It completely erases the database, blanks it out.
    Looks like I have to 'share' the file with anyone with the link for it to work, is this safe?

    Ahh gotcha, didn't realize GetEntityByKeySymbolKey provides only the first row of it.


    Code (CSharp):
    1.         // the list of all rows with Symbol=2
    2.         List<DatabaseDump> rows = DatabaseDump.GetEntitiesByKeySymbolKey("2");
    3.         var sum = 0;
    4.         //iterate over the rows and calculate the sum
    5.         foreach (var row in rows) sum += row.CostAmount;
    6.         print(sum);
    It doesn't seem I have "GetEntitiesByKeySymbolKey", I do have GetEntityByKeySymbolKey, but then I get error cant convert it to List<DatabaseDump>

    Am i missing a setup to get GetEntitiesByKeySymbolKey?
     
  9. BansheeGz

    BansheeGz

    Joined:
    Dec 17, 2016
    Posts:
    364
    1) This is correct, you need to share it and I do not think it's safe
    If you have some private data, do not leave it in the spreadsheet, used by LiveUpdate addon, move it to another private spreadsheet (or vice versa, move LiveUpdate data to a new shared spreadsheet)

    2) Visualization API does not return error codes, it returns some HTML page instead for some reason
    Use the URL from my previous message to make sure that setup is correct (if it's correct, the data.csv file should be downloaded)

    3) Make sure LiveUpdate addon settings contains only tables, you want to update from GoogleSheet
    59.png
    If your GoogleSheets data contains valid BGDB IDs (under _id column), you can disable "Remove orphaned" parameter to prevent database rows removal when you run data importing
    60.png
    But it will work properly only if every row in your sheet has a valid ID under _id column, otherwise it will result in duplicate rows inserting every time you run import
    61.png

    Most probably because you created a unique key
    If the key is unique, there should be only one single row in database with provided Symbol value, so code generator skips GetEntitiesByKeySymbolKey method
    Just delete the old key and create a new, not unique one
    Run code generator after that, a new method (GetEntitiesByKeySymbolKey) should be added right next to the GetEntityByKeySymbolKey method
    62.png
     
  10. BansheeGz

    BansheeGz

    Joined:
    Dec 17, 2016
    Posts:
    364
    @zKici
    If you are developing some Unity Editor tool, use FindEntity/FindEntities methods instead of GetByKey methods.
    FindEntity/FindEntities methods are slower, but they are very reliable
     
    zKici likes this.
  11. SoftwareGeezers

    SoftwareGeezers

    Joined:
    Jun 22, 2013
    Posts:
    902
    I'm trying to get a WebGL build for the first time. Reading the docs, it implies I can't use an embedded database and have to host a Google Sheets rather than local data. Is that the case? Can I save local versions for player runtime changes?
     
  12. BansheeGz

    BansheeGz

    Joined:
    Dec 17, 2016
    Posts:
    364
    BGDatabase works on WEBGL the same way as on other platforms (with some minor limitations) https://forum.unity.com/threads/bg-...save-load-support.529740/page-10#post-8537573

    As far as I know, there is no access to local file system on WEBGL.
    Data can only be saved to indexedDb.
    It looks like Unity PlayerPrefs uses indexedDb to save the data (with 1Mb limit)
     
    Last edited: Jul 28, 2023
  13. zKici

    zKici

    Joined:
    Feb 12, 2014
    Posts:
    438
    I deleted the key and added it again;
    upload_2023-7-28_12-56-3.png
    Re-run codegen, and still:

    upload_2023-7-28_12-56-20.png
    No GetEntitiesByKey is generated , maybe im doing something wrong
     
  14. SoftwareGeezers

    SoftwareGeezers

    Joined:
    Jun 22, 2013
    Posts:
    902
    Okay, so I do have to host my DB on Google Sheets or a web server.

    What happens with local data? My game has collectible cards and I record the collected cards back into the local DB. How's that handled on a shared remote Sheets file?

    Does the local file get saved under IndexedDB in the browser? My DB is only 11kb at the moment and will always be well under the 1 MB limit.
     
  15. BansheeGz

    BansheeGz

    Joined:
    Dec 17, 2016
    Posts:
    364
    The key should be non-unique
    When you are creating the key, make sure to not toggle on "Unique" parameter
    73.png

    After the key is created, check key's "Config", it should be equal to {"IsUnique":false}
    74.png
    Run the code generator after that, and the method should appear.
     
  16. BansheeGz

    BansheeGz

    Joined:
    Dec 17, 2016
    Posts:
    364
    You can try to use indexedDb to save the file locally
    Not sure if there is any way to share this saved data among different browsers

    I do not know how to use GoogleSheet for this task, I think it is not appropriate for this
    Maybe it's possible with custom scripts or extensions, but BGDatabase can not handle it
    Probably, you need a web server or some cloud service instead, allowing to identify the user somehow and save/load some data for this particular user
    1) When you want to save the data, call SaveLoad add-on Save method.
    This method returns a binary array.
    You need to store this data in persistent storage, pass this array to web server along with user identification information
    2) When you want to load data, call web server and provide user identification
    Once the web server returned a binary array (the data, produced by SaveLoad add-on Save method earlier), pass it to the SaveLoad add-on Load method.

    I think there should be many services, providing such features
     
  17. SoftwareGeezers

    SoftwareGeezers

    Joined:
    Jun 22, 2013
    Posts:
    902
    To be clear, I don't want a cloud-based save for the DB. ;) I want a local save file. I design and populate the DB inside Unity and include that in the game executable. I then update it locally at runtime. I'm just trying to understand the workings of WebGL in contrast to PC and mobile app builds.
     
  18. BansheeGz

    BansheeGz

    Joined:
    Dec 17, 2016
    Posts:
    364
    Oh, I see, sorry, in this case indexedDb is probably the best bet
    File Exists/ReadAllBytes/WriteAllBytes methods should work
    Code (CSharp):
    1.         string filePath = Path.Combine(Application.persistentDataPath, "someFileName");
    2.         //loading example
    3.         if (File.Exists(filePath))
    4.         {
    5.             byte[] fileData = File.ReadAllBytes(filePath);
    6.         }
    7.         //saving example
    8.         File.WriteAllBytes(filePath, fileData);
    9.  
    but after saving, you need to explicitly flush content to make it persistent by calling a JavaScript function
    JavaScript function code can be found here: https://docs.unity3d.com/Manual/webgl-debugging.html
    This solution should probably work: https://forum.unity.com/threads/how-does-saving-work-in-webgl.390385/#post-3689683

    Another alternative is to use Unity PlayerPrefs class, but it has 1 Mb limit, and it does not support binary array (binary array can be converted to string before saving) and after setting parameter you need to call PlayerPrefs.Save method
     
  19. zKici

    zKici

    Joined:
    Feb 12, 2014
    Posts:
    438
    What is the easiest way to clear / delete all entity rows of a db?

    I'm speculating this is not a good thing to do: DatabaseDump.MetaDefault.Delete()?
     
  20. BansheeGz

    BansheeGz

    Joined:
    Dec 17, 2016
    Posts:
    364
    This code deletes "DatabaseDump" table itself.
    The "DatabaseDump" table rows can be deleted by the following line of code.
    Code (CSharp):
    1. DatabaseDump.MetaDefault.DeleteEntities(DatabaseDump.MetaDefault.FindEntities(null));
    If you want to delete all database rows, no matter which table they belong to, use this code
    Code (CSharp):
    1.         for (var i = 0; i < BGRepo.I.CountMeta; i++)
    2.         {
    3.             var meta = BGRepo.I.GetMeta(i);
    4.             meta.DeleteEntities(meta.FindEntities(null));
    5.         }
     
    zKici likes this.
  21. BansheeGz

    BansheeGz

    Joined:
    Dec 17, 2016
    Posts:
    364
    There is a trick, which helps to test different code snippets quickly
    Create DBCodeTester.cs script
    Code (CSharp):
    1. using System;
    2. using BansheeGz.BGDatabase;
    3. using BansheeGz.BGDatabase.Editor;
    4. using UnityEditor;
    5.  
    6. public static class DBCodeTester
    7. {
    8.     [MenuItem("Tools/DB code tester")]
    9.     public static void TestCode()
    10.     {
    11.         BGEditorUtility.ExitIf(BGRepoWindow.Active && BGRepoWindow.Instance.RepoChanged, "Save database before running DB tester");
    12.    
    13.         //place your code here
    14.         // DatabaseDump.MetaDefault.DeleteEntities(DatabaseDump.MetaDefault.FindEntities(null));
    15.     }
    16. }
    and put it under Editor folder somewhere
    88.png
    Replace
    Code (CSharp):
    1. // DatabaseDump.MetaDefault.DeleteEntities(DatabaseDump.MetaDefault.FindEntities(null));
    this line with the code you want to test
    Open BGDatabase window before running the code.
    To run the code, use "Tools" menu
    89.png
    After code is executed, review the changes in BGDatabase window, then click on "Reload" button to revert the changes or "Save repo" button to save the changes
    90.png
    This is probably the fastest way to test different code snippets
     
    Last edited: Jul 31, 2023
    SoftwareGeezers and zKici like this.
  22. zKici

    zKici

    Joined:
    Feb 12, 2014
    Posts:
    438
    Thanks that definitely helps, i hope others find it and save time testing =)

    I am personally using Odin with this project so [Button] has been a time saver.
     
    BansheeGz likes this.
  23. jh092

    jh092

    Joined:
    Sep 2, 2018
    Posts:
    52
    Hi there, have recently purchased BG Database, thank you.

    I am using BGDataBindingBatchGO and would like to bind (and reverse bind) to one of my game objects position. The problem I am having is I cannot see how to bind to localPosition, the only option I have is Position.

    Is there a way to bind to Transform.localPosition using BGDataBindingBatchGO or do I need to resort to writing some code for that?

    Many thanks and best wishes from Australia.

    John
     
    BansheeGz likes this.
  24. BansheeGz

    BansheeGz

    Joined:
    Dec 17, 2016
    Posts:
    364
    Hi, John, thank you for buying our asset and for the kind words!
    I've sent you an updated package in a private message, sorry for the inconvenience!
     
  25. jh092

    jh092

    Joined:
    Sep 2, 2018
    Posts:
    52
    Thank you so much for your amazing help!
     
    BansheeGz likes this.
  26. sampenguin

    sampenguin

    Joined:
    Feb 1, 2011
    Posts:
    64
    Hi there, first off I love BGDatabase and have been using it for years, great asset!

    I'm currently having an issue when building for Android that I think is coming from the plugin, hoping you can help or have some ideas. I have a larger project that has been building fine for years on several platforms (Android, iOS, Win64). Runs perfectly in editor.

    But now when I try to build for Android, I get this single error and I'm really at a loss for where to look... googling comes up with a few similar hits but not the same problem.

    Building Library\Bee\artifacts\Android\d8kzr\54h5eddtozdg.o failed with output:
    D:\project\Library\Bee\artifacts\Android\il2cppOutput\cpp\GenericMethods__18.cpp(36510,9): error: cannot convert 'ToHit_t3AF3ABD05F25D743CB5F55EF5822A7984E3C71CA' to 'int32_t' (aka 'int') without a conversion operator
    return static_cast<int32_t>(___0_instance);
    ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    1 error generated.



    Unity v.2022.3.7f1
    BGDatabase 1.8.5
    IL2CPP
    using Addressables with a successful asset build if that matters.

    The only clue I can come up with from that message is 'ToHit_' which is a prefix used on one string field in generated code from BGDatabase, but that big gnarly string afterwards is not coming up in any searches of my solution, nor does it seem to match the database's internal ID for that field.

    It all previously worked in several older versions of Unity and older versions of lots of plugins/package combos.

    I've tried clean builds, totally wiping the Library folder, etc.

    Anyone else seen this or have any ideas? Suggestions or spitball ideas appreciated!
    (this is a cross post also at https://forum.unity.com/threads/failing-to-build-cannot-convert-something-to-int32_t.1484085/)
     
  27. BansheeGz

    BansheeGz

    Joined:
    Dec 17, 2016
    Posts:
    364
    Hi,

    Unfortunately, we were not able to reproduce this issue
    If you do not mind, could you, please, send me your project in a private message or by email?
    We do not need any 3D models/textures/animations/audio assets, only C# scripts and DLL files, so you can copy your project and delete all these assets if you want to. Also, please, delete all sensitive information if your project has it
    Add the following folders (Assets, Packages, ProjectSettings, UserSettings) to the archive (zip) file, upload it to the cloud drive and send a link to me
    Thank you
     
  28. sampenguin

    sampenguin

    Joined:
    Feb 1, 2011
    Posts:
    64
    Just wanted to update you: After chasing this issue for 5 weeks (with no help from Unity) I just discovered this:
    Switching the il2cpp Code Generation configuration to "Faster (smaller) builds" from "Faster Runtime" does not produce the error. Who knows why.

    I'm also fairly certain it has nothing to do with BGDatabase as I painstakingly created and built a mirror project one plugin at a time, and recreated my exact database (by importing the .bytes file) and was never able to reproduce the error in that clean project. It's 100% a bug in Unity's il2cpp compiler when Faster Runtime is selected.
     
    BansheeGz likes this.
  29. BansheeGz

    BansheeGz

    Joined:
    Dec 17, 2016
    Posts:
    364
    Thank you very much for the update!
     
  30. SIWWC

    SIWWC

    Joined:
    Oct 31, 2017
    Posts:
    13
    Hi, I want to know, can I use it outside of Unity? only use the import excel to c# structure and data, load data and get data in runtime, the two functionalities, because I hope that I don't have to modify the data system when I leave from the Unity.
     
  31. BansheeGz

    BansheeGz

    Joined:
    Dec 17, 2016
    Posts:
    364
    Hi,
    1) Which game engine are you going to use?
    2) Which target platform(s)?
    3) Do you want to import Excel data in runtime or inside editor (during game development)?
     
  32. SIWWC

    SIWWC

    Joined:
    Oct 31, 2017
    Posts:
    13
    I am using the unity, but I want to make preparation for changing game engine in the future, so I want to know if it can be used outside of unity. I would like to use excel software for data configuration when not using unity. at that moment, I hope that it can support importing data from excel file, so I can continue using BGDatabase to manage my data, instead of changing the way of managing data, it would be a big trouble.
     
  33. BansheeGz

    BansheeGz

    Joined:
    Dec 17, 2016
    Posts:
    364
    1) The Editor part (BGDatabaseEditor.dll, mainly responsible for BGDatabase window GUI inside Unity Editor) can not run outside of Unity Editor. It relies heavily on the Unity GUI system. Maybe some day we will port it to some other game engine (we're not sure if this is a good idea)

    2) The runtime part (BGDatabase.dll) can run outside of Unity with some minor changes and limitations if the runtime environment supports managed DLL code execution. We ran it in a standalone C# project and inside Net enabled version of Godot on Windows, and it looks like it works ok. I'm not sure about NPOI library DLLs (Excel library we use), we could test it as well. We will upload a modified standalone version of BGDatabase.dll to our website ("Downloads" page https://www.bansheegz.com/BGDatabase/Downloads/ ) after some testing in case somebody is interested in it.

    EDIT: standalone runtime is available https://www.bansheegz.com/BGDatabase/Downloads/Standalone/
     
    Last edited: Oct 22, 2023
  34. SIWWC

    SIWWC

    Joined:
    Oct 31, 2017
    Posts:
    13
    Oh, Thanks you so much, you are so responsible, apparently I can use it with no worry.
     
  35. Irishall

    Irishall

    Joined:
    Dec 9, 2016
    Posts:
    16
    hello. To create an inventory system, I created a 'PlayerData' table and connected the item table using relationMultiple Type.

    db.png

    And I wrote the following simple code
    E_Item item = E_Item.GetEntity(0);
    E_PlayerData.GetEntity(0).f_items.Add(item);

    But nothing happened: the item was not added to the Database, and the List Count remained unchanged.

    What am I missing - is the relationMultiple Entity a structure that can't be added or removed during runtime?
     
    Last edited: Oct 17, 2023
  36. Irishall

    Irishall

    Joined:
    Dec 9, 2016
    Posts:
    16
    Oh, never mind. I knew I could use f_items_Add.
     
  37. jh092

    jh092

    Joined:
    Sep 2, 2018
    Posts:
    52
    Hi there,

    In my game when I do a save the entire database is saved, I use this code and it works fine:

    Code (CSharp):
    1. var bytes = BGRepo.I.Addons.Get<BGAddonSaveLoad>().Save();
    2. File.WriteAllBytes(GetDatabaseFilename(), bytes);
    My question though, how could I save just a single table (meta) rather than all the tables?

    Many thanks and best wishes from Australia

    John
     
  38. BansheeGz

    BansheeGz

    Joined:
    Dec 17, 2016
    Posts:
    364
    Hi, John,

    "SaveLoad" addon's "Merge settings" can be used to include/exclude tables/fields from data saving and loading https://www.bansheegz.com/BGDatabase/Addons/SaveLoad/#mergesettings
    It's the same settings, which are used during exporting/importing data to Excel or Google Sheets. https://www.bansheegz.com/BGDatabase/ExportImport/#mergeSettings

    Here is a step-by-step guide (I will use this simple example project- https://www.bansheegz.com/BGDatabase/Downloads/Example2DBasic )
    1) Turn off global parameters
    2.png

    2) Press on "Create custom settings" button next to the table, you want to include ("Player" table in the screenshot below). 4 additional toggles will show up
    3.png

    3) If you do not create/delete rows in runtime, the settings are very simple- just turn on "Update matching" toggle
    Optionally, turn on "Choose fields to update" toggle to include only certain fields(by default all fields are included).
    In our example "name" field is excluded
    Included table and fields should be highlighted with green color
    4.png

    4) If you create/delete rows in runtime, you can use "Add missing" and "Remove orphaned" toggles
    These settings are ignored during saving and only affect how rows are processed during saved data loading
    When "Add missing" is activated, all rows with "missing" status (i.e. rows exist in saved data but not in default database) will be added to database
    When "Remove orphaned" is activated, all rows with "orphaned" status (i.e. rows exist in default database but not in saved data) will be deleted from database
    There is also an advance option to control which rows should be added/deleted by using a row controller class (it allows to skip certain rows during both saving and loading) https://www.bansheegz.com/BGDatabase/ExportImport/#rowlevel , an example of using row controller can be found here: https://www.bansheegz.com/BGDatabase/Addons/SaveLoad/#rowlevelexample
    In our example 2D project, we do not use row controller, and we have both "Add missing" and "Remove orphaned" toggles turned on for "Collectibles" nested table
    5.png

    Please, let me know if you have any questions
     
    Last edited: Oct 28, 2023
  39. jh092

    jh092

    Joined:
    Sep 2, 2018
    Posts:
    52
    Thank you for all the super helpful detail, very much appreciated.
     
  40. gekidoslair

    gekidoslair

    Joined:
    Sep 7, 2012
    Posts:
    127
    Hey all

    We're running into a strange issue parsing floats from Google Sheets?

    a float value of 1.25 is coming into the game db as 125 - basically it's ignoring the decimal and just spitting out an integer equivalent?

    The data structure is correct, the fields are set as float on the Unity side

    It's very strange, any ideas?
     
  41. BansheeGz

    BansheeGz

    Joined:
    Dec 17, 2016
    Posts:
    364
    Hello,
    We have added an option to change number formats
    I've sent an updated packages to you by email
     
  42. maart

    maart

    Joined:
    Aug 3, 2010
    Posts:
    82
    Can we get get playmaker actions for FindEntity/FindEntities?
     
  43. BansheeGz

    BansheeGz

    Joined:
    Dec 17, 2016
    Posts:
    364
    1. FindEntity/FindEntities methods accept a function as a parameter and this function returns true if a row comply with the filter or false if it does not
    For example,
    31.png
    Is it possible to implement function parameter with Playmaker somehow?

    2. Current solution is to iterate the rows one by one
    For example (FindEntity method),
    2.1 read rows count
    32.png
    2.2 loop
    33.png
    2.3 read row value and compare with target value. If values are equal, exit the loop (index variable is target row's index)
    34.png
     
  44. BansheeGz

    BansheeGz

    Joined:
    Dec 17, 2016
    Posts:
    364
    Another alternative to FindEntity/FindEntities methods is to use a key and GetByKey method.
    A key contains 1..n fields and it can retrieve the row(s) without iterating over each row.
    You need to provide a value for each field, included into the key, and the key returns the row(s) with such values
    It's not a generic approach, unlike FindXXX methods, but when it's possible to use a key, it's a good idea to use it.
    More information about the keys https://www.bansheegz.com/BGDatabase/Misc/KeysAndIndexes/#keys

    For each key Playmaker node {TableName}GetByKey{KeyName} is generated
    For example
    1. If we create a key "intFieldKey" with "intField" field included
    35.png
    2. we can use {TableName}GetByKey{KeyName} (in my case it's P_MyTableGetByKeyintFieldKey) node to search the rows with specified "intField" value, for example, to find the first row with "intField"==1
    36.png
     
  45. mdwallin

    mdwallin

    Joined:
    May 1, 2018
    Posts:
    4
    Hi I am running in to these warning errors when using code generation:

    Assets\BansheeGz\Generated.cs(13,34): warning CS0436: The type 'BGEntity' in 'D:\GIT\FlowerBeepBoop\My FlowerBeepBoopUnity\Assets/BansheeGz/BGDatabase/Scripts/Database/Core/Objects/BGEntity.cs' conflicts with the imported type 'BGEntity' in 'BGDatabase, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null'. Using the type defined in 'D:\GIT\FlowerBeepBoop\My FlowerBeepBoopUnity\Assets/BansheeGz/BGDatabase/Scripts/Database/Core/Objects/BGEntity.cs'.



    Assets\BansheeGz\BGDatabase\Scripts\Addons\CodeGen\BGAddonCodeGen.cs(19,43): warning CS0436: The type 'BGAddon' in 'D:\GIT\FlowerBeepBoop\My FlowerBeepBoopUnity\Assets/BansheeGz/BGDatabase/Scripts/Database/Repo/Addons/BGAddon.cs' conflicts with the imported type 'BGAddon' in 'BGDatabase, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null'. Using the type defined in 'D:\GIT\FlowerBeepBoop\My FlowerBeepBoopUnity\Assets/BansheeGz/BGDatabase/Scripts/Database/Repo/Addons/BGAddon.cs'.


    and 999+ more.
    I'm not sure how to go about fixing this.
    My database seems to be set up correctly and is importing/exporting fine. But I'm yet to be able to use it in my code yet.
     
  46. BansheeGz

    BansheeGz

    Joined:
    Dec 17, 2016
    Posts:
    364
    Hi,

    Most probably you unpacked the package with C# source files
    There are 2 DLL files in the asset
    1) Runtime DLL- Assets/BansheeGz/BGDatabase/Scripts/BGDatabase.dll .This DLL is bundled with your game
    2) Editor GUI DLL - Assets/BansheeGz/BGDatabase/Editor/Scripts/BGDatabaseEditor.dll .This DLL is responsible for BGDatabase window GUI inside Unity Editor

    And there are 2 packages with C# source files right next to these DLLs
    They contains the C# source files, which were used for creating DLL files
    Source files are provided for referencing/debugging purpose, but normally DLL files should be used instead
    49.png

    There are 2 ways to fix the problem:
    1) Select Assets/BansheeGz/BGDatabase/Scripts/ in the Project view and delete all subfolders (as shown on the screenshot below)
    50.png
    Also check Assets/BansheeGz/BGDatabase/Editor/Scripts folder and delete all subfolders as well if any
    51.png

    2) Alternatively, re-import BGDatabase asset by deleting Assets/BansheeGz/BGDatabase/ folder and importing BGDatabase asset again
     
  47. mdwallin

    mdwallin

    Joined:
    May 1, 2018
    Posts:
    4
    Thank you, this worked and now everything works!
    Maize
     
    BansheeGz likes this.
  48. aleksei-antipin

    aleksei-antipin

    Joined:
    Oct 17, 2022
    Posts:
    1
    Hello. I have a question about how live update works. I made a test application in which I downloaded a patch for the database as json. I expected the patch to be applied automatically the next time I started the application, but I found that the database was initialized with default data. Please tell me, is it possible to cache patches and automatically apply them when the application is restarted?
     
  49. BansheeGz

    BansheeGz

    Joined:
    Dec 17, 2016
    Posts:
    364
    Hello,

    We have added an option to save remote data locally and apply it in case data loading fails
    I've sent an updated package to you in a private message

    It works like this:
    1) "Live Update" add-on tries to load remote data
    2) If data loading is successful, add-on saves remote data in local file
    3) If data loading fails, add-on checks if local file exists and if it's found add-on loads data from local file

    To enable this feature, toggle "Enable persistent cache"(UPD: we will rename it to "Apply last data on failure", cause it's not a cache really) parameter on as shown on the screenshot below
    52.png
    Also, if you switch log level to "Detailed" and enter game mode, you will be able to see log messages, related to data loading
    53.png

    Please, let me know if new feature works as expected
     
    Last edited: Dec 11, 2023
  50. thatscraigz

    thatscraigz

    Joined:
    Mar 27, 2015
    Posts:
    100
    Hello! :)

    Is there any way to 'unload' data or revert back to default database values?
    Either specific entities or the entire database?

    I am using Playmaker, and right now usually when changing user save profiles I've been jankily loading a hidden 'default' user profile in a new scene then loading back into the primary gameplay scene, but its getting a bit unweildy

    thanks!
    craig