C++ Libraries
In order to use ContentLib’s cpp libraries, you need to properly setup ContentLib as a dependency for your own mod. This has a few more steps for a C++ mod compared to a Blueprint mod.
This guide assumes you already have a working mod from following the Getting Started Guide and have added your own C++ module to it.
Get ContentLib in your Editor
Follow the directions here to set up the ContentLib libraries in your editor.
Setting up the C++ Dependencies
In order to call ContentLib functions from your C++ files, you must first include the relevant header file in normal C++ fashion. However, in order for Unreal to recognize that your plugin needs to know about ContentLib code, you must first update the build script.
In order to include the ContentLib header files you need to set it up as a code dependency first
so that the Unreal Build Tool will be able to locate the headers correctly.
Go to your ModReference.Build.cs
, which is in your mod’s /Source/ModReference
folder,
and add ContentLib as a public dependency next to "FactoryGame" and "SML"
Example: ModReference.Build.cs
PublicDependencyModuleNames.AddRange(new string[] {
"FactoryGame",
"SML",
"ContentLib"
});
Including Headers and Calling Functions
Now that you have updated your uplugin and your .Build.cs
file, its important that you
regenerate visual studio build files.
Now you should be able to include the ContentLib header files in your own.
As an example, let’s use the Content Lib Class Default Object Blueprint Function Library to make a CDO edit from a string.
At the top of your header file:
Example: Someclass.h
#include CLCDOBPFLib.h
Now, in your class, you can call GenerateCLCDOFromString.
This could be ran in a Game Instance Module’s post init phase, for example.
Example: Someclass.cpp
// Set up some JSON for a CDO
FSTRING json = TEXT(R"({
"$schema": "https://raw.githubusercontent.com/budak7273/ContentLib_Documentation/main/JsonSchemas/CL_CDO.json",
"Class": "/Game/FactoryGame/Resource/Parts/GoldIngot/Desc_GoldIngot.Desc_GoldIngot_C",
"Edits": [
{
"Property": "mDisplayName",
"Value": "Gold Ingot"
}
]
})");
// Apply the CDO
UCLCDOBPFLib::GenerateCLCDOFromString(json, true);
Usage Examples
ContentLib exposes most of the systems it uses internally to create the "loading of text files into real content" functionality for use by any other mods.
You can also call all of the Blueprint Lib exposed functions from C++ as well.
You can look at the ContentLib source code for more examples of how each function is used.
Please consider contributing more examples to the docs here if you have some time via 'Edit This Page' in the top right.