Instantiating UObject-derived classes (ConstructObject < > and NewObject < >)

Creating class instances in C++ is traditionally done using the keyword new. However, UE4 actually creates instances of its classes internally, and requires you to call special factory functions to produce copies of any UCLASS that you want to instantiate. You produce instances of the UE4 Blueprints classes, not the C++ class alone. When you create UObject-derived classes, you will need to instantiate them using special UE4 Engine functions.

The factory method allows UE4 to exercise some memory management on the object, controlling what happens to the object when it is deleted. This method allows UE4 to track all references to an object so that on object destruction, ...

Get Unreal Engine 4 Scripting with C++ Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.