Spawning UObjects from blueprint

Hi all,

I wonder how can I spawn blueprint that inherits from UObject in another blueprint (like lvl blueprint)? There is node “Spawn Actor From Class” which spawns actors, but not UObject’s.

I know I can do it from C++, but just want to know how to do it from blueprint.

Thanks in advance :wink:

You need to write a simple method on the uclass that returns an instance of it.
You can use one of these functions: https://docs.unrealengine.com/latest/INT/Programming/UnrealArchitecture/Objects/Creation/index.html

edit:
Here’s a sample code from our project:

//HTile.h
UFUNCTION(BlueprintCallable, Category=Grid)
static UHTile* CreateHTile(UObject* owner);

//HTile.cpp
UHTile* UHTile::CreateHTile(UObject* owner)
{
	return NewObject<UHTile>(owner);
}

http://i.imgur.com/xxvRnbO.png

Hi,

thanks for an answer. I’m trying really hard to comprehend what You’ve written but to no avail :wink: Basically You want me to subclass UClass. In this sublclass (lets say UMyClass) You want me to create method

UFUNCTION()
Uobject* UMyClass::SpawnObject()
{ return NewObject((UObject*)GetTransientPackage(), this); }

Let’s say I’ve done all this. How to use such method from blueprints? Sorry for beying so slow but I’am newbie to UE4 C++.

I’ve edited my original answer with an example. Feel free to ask if you have any more questions.