Download

Need to be able to create an instance of a BP class from a BP

Hey Guys,

Currently there is no way to create a BP class instance in a BP graph. This can be easily done in C++ obviously. I want the functionality, available to me in BPs. For example; if I have a BP class MyState(it is of type Object), I want to create an instance of it using a node where I specify the class “MyState”, on the left-hand side of the node and it returns an instance via the right-hand pin of the node. This is currently not possible, as no such node exists. I believe this functionality should be present in the mainline.

I am willing to put in a PR against the master repository for 4.8, to add this feature, if there is enough interest.

Tommy.

Ok… this is what I have now. I’ve added it to the Kismet System Library under Utilities. This is what the usage looks like:

f6ae3cf07cf927b60f543e1d0a4f9c293f4d0b2d.png

The new “Create Instance From Class” node creates an instance given a value BP exposed UObject derived class.

Tommy.

PS:
Added the PR for master. It is here: https://github.com/EpicGames/UnrealEngine/pull/1060

Just out of curiosity, i always thought that instance = spawned (created) object from some class - so what’s the difference between spawned objects (by Spawn Actor From Class node) and instances? I’m not too familiar with C++, so maybe thats why i lack knowledge in this area :slight_smile:

This sounds a bit like what I was asking for in my thread about Functions and Inheritance for BP Structs.
But do you really need that cast? Spawn Actor from Class lets me directly use functions defined in that actor (or is that simply magic from the Pin there?)

It’s not so much a difference as it is use case. A spawned object is an instance of the object. The problem this node solves (at least the way I see it/would use it) is when you just want to use it as data and not a spawned object within the world.

Yep, so you can only spawn Actors (UObjects who are sub classes of AActor). This also makes them appear in the world. In this case, I want to create a data-only based object(directly from a UObject), that I manage and one that includes the functionality along with the data. I also don’t need it to appear in the world.

Tommy.

Bingo! So this is just a function I have exposed in the Kismet System Library. It is not a K2_Node implementation. Those nodes, create a typed pin using code that executes once a class is selected. Initially, I wanted to keep this simple to increase the possibility of integration with the main branch. If it gets accepted, I’ll look at making it an actual node and include a redirect from the old to the new.

Tommy.

My change is no longer required. Epic are working on similar changes internally… all I can say is… yay!!! Thanks Epic.

Tommy.

I’m so happy to hear this. A few things I originally tried to make would’ve been so easy with this feature. Maybe I’ll revisit them when we get this node. =D