Field types

← Back Changing enum type guide

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

  1. 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.
  2. Rename enum class in your IDE and switch to Unity.
  3. 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.
  4. 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:

  1. Manually
  2. Using "Settings->Enumerations" tool

OPTION #1: Changing enum type manually

  1. Let's say you have MyEnum enum, which is used in Test.enumField database field, and you want to rename enum's type name to MyEnumNewName
  2. Create the copy of MyEnum enum with some unique name, let's say MyEnumTemp
  3. Change database field's enum type (MyEnum -> MyEnumTemp). Save database.
  4. Change C# enum type name in your IDE (MyEnum -> MyEnumNewName)
  5. Change database field's enum type (MyEnumTemp -> MyEnumNewName). Save database.
  6. Delete C# temporary enum MyEnumTemp

OPTION #2: Using "Settings->Enumerations" tool

  1. Rename enum type/namespace using your IDE
  2. 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
  3. Select "Settings->Enumerations" and add enum type name mappings (Old name->New name) for each change.
  4. 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

← Back to Field types