UObject in a Blueprint

Hi!
I’m trying to having a Blueprint with an object that has some functionality that i want to reuse in other blueprints, actors, umg widgets and so on. How can i instantiate a new object in a Blueprint without having an actor as the base class to be able to spawn it in the world? Or is this the “unreal” way?
Best

In C++ funtion is called ConstructObject, if you cant find it in blueprint you canntry to expose it yourself by creating static funtion in C++ which will call ConstructObject. I assume you know some C++ as you use UObject name and pick C++ category.

No not much, i’m a java developer but trying a bit out with unreal and thats one thing i wondered about. Do you have an example for me?

Of binding exposing that function to blueprint?

in .h decleration of some class:

UFUNCTION(BlueprintCallable, Category="Objects")
static UObject* SpawnObject(UClass* ObjClass);

in cpp

UObject* ASomeClass::SpawnObject(UClass* ObjClass) {
       return ConstructObject(ObjClass);
}

ASomeClass replace with name of your class, as it is static function you can place it in any class you make

Just updating, it is available in Blueprints too. Under “Construct object from class”.
I’ve just tried this and it worked, so seems you do not need to dive into c++ to do this.

Yes they added it in later UE4 version :slight_smile: it’s old question from 2014