Getting blueprint node result when overriding UK2Node_ConstructObjectFromClass

Hello, I’m currently writing a plugin which includes noise generation. I want to provide (from C++) custom blueprint nodes that the user will be able to use to compose his own noise functions.

For this, I’m overriding UK2Node_ConstructObjectFromClass with my own BPNode_CreateNoiseModule. The BPNode_CreateNoiseModule can only create objects whose classes are subclass of my NoiseModule (for instance PerlinNoiseModule, VoronoiNoiseModule, etc.). This part is pretty easy, I’ve followed this tutorial for this.

Now, the tricky part is that I want to display a preview of the result of the NoiseModule in the blueprint node : lets say that the user use my BPNode_CreateNoiseModule to create a PerlinNoiseModule, I want to show an image in the blueprint editor showing the Perlin noise with the parameters chosen by the user.

I’m already able to generate dynamically an image and display it in a blueprint node. But I would like to be able to get the result of the node : the BPNode_CreateNoiseModule is supposed to return a fully initialized NoiseModule, I want to get a reference to this NoiseModule to create my image. Is this possible?

Hi. When you know a class of an object you want to create (inside the node class) you can just spawn a new object instance using following code

/* ActualModuleClass is UClass of module you need */
UNoiseModule* TemporaryModuleForMakingImages = NewObject<UNoiseModule>(GetTransientPackage(), ActualModuleClass, NAME_None);

To keep created instance from GC you have to store resulting object inside node’s UPROPERTY or use FGCObjectScopeGuard as I wrote here

You can use your node instead of transient package (GetTransientPackage()) if you really need not a temporary object but persistant.