Description
This guide describes how to change an enum's type name and namespace after the enum has been used in the database for enum, enumShort and enumByte fields. Starting with BGDatabase 1.9.3, changing enum type or namespace is greatly simplified. For earlier versions, please, refer to the archived content below.
The Guide for BGDatabase >= 1.9.3
- Make sure your database is saved in binary format. If you use Settings add-on and JSON format, switch to the Binary format and save the database.
- Rename enum class in your IDE and switch to Unity.
- The database should load properly, but an error will be printed in the console about being unable to load the enum type. Open enum field settings, enter the new enum type and save the database. Reload database and confirm there are no errors in the console.
- Restore the settings add-on format if it was changed in step 1.
The Guide for BGDatabase < 1.9.3
Archived guide (click to view)
Description
This guide describe how to change enum type name/namespace, after this enum was used in database enum fields. Two options are available:
OPTION #1: Changing enum type manually
-
Let's say you have
MyEnum
enum, which is used inTest.enumField
database field, and you want to rename enum's type name toMyEnumNewName
-
Create the copy of
MyEnum
enum with some unique name, let's sayMyEnumTemp
-
Change database field's enum type (
MyEnum
->MyEnumTemp
). Save database. -
Change C# enum type name in your IDE (
MyEnum
->MyEnumNewName
) -
Change database field's enum type (
MyEnumTemp
->MyEnumNewName
). Save database. -
Delete C# temporary enum
MyEnumTemp
OPTION #2: Using "Settings->Enumerations" tool
- Rename enum type/namespace using your IDE
- Switch to BGDatabase window and click on Reload button. Database will not be loaded, cause enum type can not be loaded using old name/namespace
- Select "Settings->Enumerations" and add enum type name mappings (Old name->New name) for each change.
- Click on "Reload" button. Once database is loaded, click on both "Clear the mappings" and "Save repo" buttons
Extra tip
Use custom Attribute to mark enums, which are used inside database