Code Generation Addon

Main article about Code Generation addon is here

Description

Code Generation addon makes accessing BGDatabase API easier. Once this addon is enabled - database will use generated classes instead of basic BGEntity while populating table rows. Each generated class has additional properties/methods to access the data.

What properties/methods are generated?

The full list of generated methods/properties can be found in main article about code generation)

Examples

All our example projects use CodeGen addon

Short explanation

Here is an example: lets assume you have a table named "MyTable" which has one single field: intField of type int.

To access it without CodeGen you would use something like this: var intValue = entity.Get<int>("intField");

As you can see, you should provide field name and field type.

With CodeGen you would use something like this var intValue = entity.intField;

So all fields with their types will be generated for you for maximum ease of use.

The only drawback CodeGen has - you need to regenerate the classes each time you change database structure (e.g. adding/removing tables or fields)

Parameter name Description
Code Generator Class to use for code generation (use default one)
Source file Source file to use for generated C# classes. All classes will be put into one single .cs file, which should be under your project folder
Package Package (C# namespace) for generated classes. For example MySpace. You can safely leave this setting blank.
Class names prefix Prefix to use for each class name. So if you use E_ prefix, the final class for MyTable table will be named E_MyTable. We have multiple code generators, so using different prefixes for different code generators helps to differentiate generated classes and avoid naming collisions
Field names prefix Prefix to use for each generated property name. So if you use f_ prefix, the final name for intField field will be f_intField. You can safely leave this setting blank.
Entities prefix [Optional] Optionally, you can generate properties for each entity. After that, you can access each entity directly using these properties. Read more about it here: Generate a property for each entity
Reference class postfix/Reference list class postfix [Optional] Optionally, you can generate reference class, which can be used to reference database row easily. Read "Reference classes" section in the main article for more information. Set these parameters to valid C# literals (for example _Ref and _List_Ref) to enable code generation
Raw properties postfix (version >= 1.8.19) If the postfix is set, additional {FieldName}{RawPropertyPostfix} properties are generated for setting value without firing events. Standard setters trigger events, which incur a performance penalty. Simple fields (such as integers, floats etc.) allow for direct value assignment, bypassing event triggers. If fields are not utilized in keys or indexes and do not have any event listeners attached (note that data binders with the "Live" parameter enabled can attach events to these fields) values can be set directly without the overhead of firing events. Database Editor GUI is also using events to detect when the window should be repainted, so if you are using only raw setters, the database Editor GUI may not be updated properly. In this case, you can enable the 'Repaint database window every frame in play mode' option in Settings > Preferences. However, be aware that this can be performance-intensive and should only be used as a last resort.