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

I want to do this with python or blueprints or both. With editor tools I can only create a duplicate but I’m not sure where or how to get a factory just to make classes.

First, you don’t “make classes,” because classes are code. You write the code.

Second, why do you need a “factory”? What is this “factory” supposed to do, that a function like “Spawn Actor From Class” won’t already do for you?

Are you talking about “spawner actors”? Those are actors of some class that you make, that, at runtime, on some timer, or at some event, will call “Spawn Actor From Class” to create a new instance of some class/blueprint, in the world.

You absolutely do ‘make classes’. As in create classes. What do you not understand? Create classes the same way you create them by right clicking in the content browser and selecting create blueprint class, or interface, or whatever you want. There’s even a create asset node you can access with asset tools. However, it has an input pin for a factory.

Gotcha – that additional context is very helpful to illustrate what you actually mean!

You showed up to ridicule his very valid question because you didn’t understand it, but once he helped you understand, you disappear?

1 Like

Because I didn’t have an answer, once I understood the question.
If you believe that asking clarifying questions is “ridicule” then I don’t know what to say.

So, reading the code: Asset factories are not implementable or accessible through Blueprints (or Python, which largely has access to a similar API)
You will need C++ to do this.

Note that “classes” as used in the OP are generally referred to in the editor as “blueprints” or “bluepring classes” and come in a few variants – e g, an “animation blueprint” is different from an “actor blueprint” and is different from a “control rig blueprint” for example, and they have different factories.

The code does not expose the UBlueprintFactory base class, so you’ll want to wrap any such use you need into a C++ code path:

UCLASS(hidecategories=Object, collapsecategories)
class UNREALED_API UBlueprintFactory : public UFactory

Short answer:
There are variety of factory classes accessible trough Python (and most likely in BP):

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:

1 Like