Skip to content

Faction Database

Factions are retrieved from a dedicated object known as the Faction Database. Even though the Database is one of the most important classes in the system, is not a class that you will interact with directly. Instead, it will provide data through the Faction Subsystem.

It would be expected that, for some requirements, you might need to extend the current database or create one from scratch. For that matter, that are two important clases to know of:

  • The NinjaFactionDatabase base class.
  • The FactionDatabase_DataAssets default implementation.

You can create subclasses that may better fit your requirements, and define them in the Settings Panel. However, for common scenarios where you'll be defining Data Assets for your factions, the provided Database should be enough.

Configuring the Asset Manager

The default Faction Database searches for Faction Data Assets in the project and loads them into memory.

The Database uses the Asset Manager to load the Faction Assets. This means we need to configure our Faction Data Assets as Primary Data Assets in the Asset Manager Settings Panel.

Asset Manager Settings

Here's a summary of changes in the new entry:

Setting Description
Primary Asset Type Unique name used to identify this asset. The name defined in the class is FactionSetup.
Asset Base Class Base class that represents this these assets. In our case, NinjaFactionDataAsset.
Directories All content folders where assets of this type can be found. Adjust this as necessary.
Cook Rule Always cook, as this asset type is probably fundamental to all characters in the game.

Although the Data Asset Faction Database is the default database type configured for the plugin, let's make sure that it's properly defined in the Ninja Factions Settings Panel.

Factions Database Settings

Configuring the Reputation Tier Table

Depending on your needs, you may or may not require Reputation Tiers.

There's a dedicated section for this topic, but you should now that Tiers are configured in the Plugin Settings Panel or in the Database Class. This means that the Faction Database is responsible for providing Faction and Reputation Tier data.

Create a new Faction Database

The base NinjaFactionDatabase class has a lot of logic already. It only truly requires the function GetFactions to be implemented, which is precisely the function you'd write to obtain Faction Data Assets from your source.

You can implement your Database using Blueprints or C++. Here's a simple example that, instead of using the Asset Manager, will use a hardcoded collection of Data Assets.

Create Database Blueprints using the Context Menu

In your Content Browser, you can right-click within your target folder and under the "Factions" category, there's an option to create the Faction Database Blueprint!

Custom Database Example

#pragma once

#include "CoreMinimal.h"
#include "NinjaFactionDatabase.h"
#include "FactionDatabase_DataArray.generated.h"

UCLASS(DisplayName = "Faction Database: Data Array")
class PLUGINLABS_API UFactionDatabase_DataArray : public UNinjaFactionDatabase
{

    GENERATED_BODY()

public:

    // -- Begin Faction Database implementation
    virtual void GetFactions_Implementation(TArray<UNinjaFactionDataAsset*>& OutFactions) const override;
    // -- End Faction Database implementation

protected:

    UPROPERTY(EditDefaultsOnly, BlueprintReadOnly, Category = "Factions")
    TArray<UNinjaFactionDataAsset*> Factions;

};
#include "FactionDatabase_DataArray.h"

void UFactionDatabase_DataArray::GetFactions_Implementation(TArray<UNinjaFactionDataAsset*>& OutFactions) const
{
    // Easy-peasy! ;D
    OutFactions = Factions;
}

At this point, you would configure the new Database Class in the Project Settings page. It's up to you to further experiment with that or continue using the default database.

The GetFactions Function is the only one that you must implement. But depending on what you are trying to achieve, is worth knowing that there's a InitializeDatabase that can be used, to perform startup tasks.

If you override the initialization, make sure to call the super/parent implementation!

Next Steps

Now that we covered the Faction Database object, let's take a look into the Attitude Solvers, so we can understand how the Attitude is determined between faction membeers.