How on earth do I get a 'factory' to create a class or subclass?

Short answer:
There are variety of factory classes accessible trough Python (and most likely in BP):
https://docs.unrealengine.com/5.0/en-US/PythonAPI/search.html?q=factory

Simple snippet to create a ControlRig asset (you need to have ControlRig and EditorUtility plugins enabled):

factory = unreal.ControlRigBlueprintFactory
blueprint = factory.create_new_control_rig_asset(desired_package_path = ASSET_PATH)

Slightly longer answer:
Factory is a programming pattern, it’s a class that allows you to create other classes based on inputs. You don’t need to implement factory, but you need to get access to one in order to use it.

In Unreal there is the Factory class and child classes of it for the most (all?) asset types you can use in ContentBrowser. Most of them partially exposed for BP and Python, but not everything. Some of functionality can be accessed through helper class AssetTools. If you using factories directly, it can be worth to check specific implementation of it. Not all can be usable trough BP or Py, some will require you to prebuild a Task class with parameters so factory knows what you want and others will only import or may have other quirks.

Here is an example I could find that is related:

Hope this helps :slight_smile:

6 Likes