Addressables system plugin
Support for Unity's Addressables system (BGDatabase version >= 1.5.6 is required). It adds 2 Addressables loaders for all Unity asset fields.
- Use Unity version > 2018.2
- Install Unity's addressables package via package manager
- Install latest BGDatabase
- Install this package
- Create your own database as described here
- Create a table with Unity assets fields and set loader=Addressables or loader=AddressablesByGuid via gear icon
- Addressable: asset address is stored as database value in human readable form. Cons: you can not change address after value was assigned to database again
- AddressableByGuid: asset Guid is stored as database value. Cons: Guid is just a set of bytes, it's not readable
How to read values:
- [Legacy] Usual method, by reading field value. Assets preloading is required for this method, please see below for more details (not recommended)
Instead of reading field value the usual way, you can retrieve asset address from database and use this address directly with Addressables system.
No preloading is required in this case.
Each unity asset field is implementing BGAddressablesAssetI interface, which can be used to read asset address (using method
string GetAddressablesAddress(int entityIndex)).
We recommend method #2, cause it does not involve running additional code(preloading) and it's as robust as Addressables system is.
This AddressablesQuickStart project has examples for both techniques
If you use Playmaker you can use this custom action. No preloading required.
Preloading [Legacy, not recommended]:
If you access unity field with addressables loader like you normally do (How to read values, method # 1, mentioned above),
you need to preload required values, otherwise values will not be resolved successfully (null will be returned).
You have full control over which values you want to preload: you can use database values or Addressables system to decide which values to preload.
Preloader script is included into the package(Assets\BGDatabaseAddressables\ScriptsNoDll\BGAddressablesPreloader.cs). It preloads all values from all rows/fields, but you can modify it to preload only required part of the database. Completed() method is invoked after all assets are preloaded.
Tesing if Addressables system setup properly:
Some people experience issues while setting Addressables system up. In this case, use this script to test if Addressables works correctly.
- Create empty scene
- Attach the script to any GameObject
- Assign it's Address parameter to some valid address from your Addressables system
- Run the scene and make sure asset was loaded successfully (no exceptions in the console)
- Addressables packages v.1.8.3-1.9.2 have a bug, preventing loading sprites from SpriteAtlases correctly using atlasAddress[spriteName] syntax (invalid key exception is thrown). If you use sprites with SpriteAtlases and GetAddressablesAddress method (without preloading), the solution would be to downgrade to Addressables v.1.7.5 or upgrade to next version after 1.9.2. More information is available here
|1.2||March 06, 2020||Update for BGDatabase v.1.5.6|
|1.1||September 20, 2019||Update for BGDatabase v.1.4|
|1.0||January 09, 2019||Initial release|