= Customizable Objects, Classes and Populations
TODO: Diagram of how this works at user level
[[mutable/unreal-engine-4/user-documentation/population/#population|Populations]] generate random [[mutable/unreal-engine-4/user-documentation/basic-concepts/#customizable-object-instance|Customizable Object Instances]] based on their internal configuration, which consists of [[mutable/unreal-engine-4/user-documentation/population/#population-class|Population Classes]] and relative chances to appear.
Each Population Class is based on a single [[mutable/unreal-engine-4/user-documentation/basic-concepts/#customizable-object|Customizable Object]], and it defines its typical traits. It does so by choosing which [[mutable/unreal-engine-4/user-documentation/basic-concepts/#parameter |Parameter]] values should be able to be produced on random Customizable Object Instances and how often.
= Population Class
This is a new type of asset added to Unreal Engine.
It defines which Customizable Object is this class based on and what are its Characteristics.
Each Characteristic is a limit to what are acceptable options for one Parameter and its relative chances of appearing on random Customizable Object Instances of this Population Class generated by a Population. Depending on the type of Parameter, it allows setting how common it is to find certain options, choosing a single value as valid, or even using a curve to define the chances of appearence of continuous numeric values. The class also allows blacklisting and whitelisting integer and boolean Parameters via [[mutable/unreal-engine-4/user-documentation/population/#tags|tags]], both globally and on individual Parameters.
You can create Customizable Population Classes from the Content Browser Add New menu:
This is a new type of asset added to Unreal Engine.
It produces random Customizable Object Instances according to how it's set up: which Population Classes and how often are they used.
This allows a single Population to create Customizable Object Instances from multiple different Customizable Objects and/or from the same Customizable Objects but from different Population Classes.
You can create Customizable Populations from the Content Browser Add New menu:
Its Customizable Object Instance generation algorithm is updated each time the Population or the Population Class are saved, using the Parameters from the Customizable Objects of each Population Class at that time.
It's also updated when the project is packaged, so it's ensured to be up to date.
= Population Class Editor
The left panel edits the Population Class. It's used to:
(1) Choose which Customizable Object it is based on.
(2) Define characteristics of that class.
(3) Set the global class tag whitelist and blacklist.
There is at most one characteristic per parameter that the base Customizable Object has.
Each Characteristic is defined using Constraints: they define what values will be found in random Customizable Object Instance of the Population Class, for each Parameter, and their chances.
Different types of Constraints can be used to define a Characteristic depending on the Parameter type.
Any Parameter that is not specified with a valid Characteristic will end up randomized by the Population Class, with each of its options having equal chance of being on a Customizable Object Instance generated from this particular Population Class.
The central panel defines the Customizable Object's Population Tags. These Tags can be used and modified from any Population Class that shares this Customizable Object. Tags are used to control what ends up in the random Customizable Object Instances via the global whitelist and blacklist or setting Characteristics that use constraints of type "Tag".
The panel allows you to:
(4) Add and remove Tags, to be able to use them. The text box can be used to add new Tags. Below it, there is the list that shows the existing Tags, where they can be deleted.
(5) Choose which parameter are we going to be setting Tags for.
(6) Define what Tags are appliable to each of the options of the enum.
The right panel (7) shows a preview of what would be generated with the current settings.
They are generated each time the "Test Population Class" button (8) is pressed. The amount of Customizable Object Instances generated can be defined using the down arrow next to the button, the default is ten.
Finally, the "Generate Instances" button (9) can be used to generate random Customizable Object Instance assets. These are normal Customizable Object Instances, to use as game assets from the editor, and they will have nothing else randomly generated after being created.
To generate random Customizable Object Instances at runtime, you can use the functions "Generate Population" and "Regenerate Population" found in the "Population" asset. It is illustrated at [[mutable/unreal-engine-4/user-documentation/population/create-use-population/|the step by step tutorial based on the village demo]].
= Population Tags
To use a Tag, it first has to be created (4), then assigned to some Parameter options (6) (5), and finally used on whitelists and/or blacklists either globally (3) and/or on a Constraint that affects a single Parameter (2).
Tags are created on the tag manager text box.
Tags are designed to be assigned to each of the options of an enum Parameter individually.
Then, they are used to indicate that certain Parameter options should be found or not on Population Classes. That is done by whitelisting and blacklisting those Tags. This is defined later in this section, with a truth table at the end.
Tags are stored in the Customizable Object, so different Population Classes of the same Customizable Objects have access to the same Tags, on the same Parameters and Parameter options.
Assigning Tags to each of the options of an enum is the main purpose of Population Tags, and together with blacklists and whitelists allow to manage a growing amount of options without manually modifying each Population Class constraint that depends on it each time an option is added or removed.
Each Population Class has a general whitelist and blacklist, to define in broad strokes what will and will not be found on Customizable Object Instances generated from that Population Class.
Integer and boolean Parameters can also have Tag Constraints set on them. Those Constraints override the global whitelists and blacklists, but only for the specific Caracteristic that defines the Tag Constraint. This allows us to specify exceptions to the general whitelists and blacklists to fine tune specific Parameters of Population Classes.
Tag lists follow this logic until some condition applies:
1. If none of the Tags on any option of an enum are in any tag list for this Parameter: All of it's options have the same chance to appear.
2. If one of the Tags of at least one option of an enum is in a Constraint list for this Parameter: Only enum options that don't have any Tag on the Constraint blacklist appear. If any enum option Tag is in the whitelist, only options that have some Tag in the whitelist and none in the blacklist appear. The table at the end describes the result:
3. The same as point 2. but on global lists. If one of the Tags of at least one option of an enum is in a global list for this Parameter: Only enum options that don't have any Tag on the global blacklist appear. If any enum option Tag is in the whitelist, only options that have some Tag in the whitelist and none in the blacklist appear. The table at the end describes the result:
Truth table for whitelists and blacklists:
| The enum option has a Tag in whitelist | The enum option has a Tag in blacklist | Another option of the same enum has a Tag in the whitelist | Can this enum option appear on random Customizable Object Instances?
| ----- | ----- | ----- | -----
| no | no | no | **YES**
| **yes** | no | no | **YES**
| no | **yes** | no | **NO**
| no | no | **yes** | **NO**
| **yes** | **yes** | no | **NO**
| **yes** | no | **yes** | **YES**
| no | **yes** | **yes** | **NO**
| **yes** | **yes** | **yes** | **NO**
(NOTE) There's [[mutable/unreal-engine-4/user-documentation/population/create-use-population/|a step by step tutorial based on the village demo]] where the basics are put into practice. It's recommendable to go trough it.