Is there any way in C++ to replace the default "Construct Object from Class" BP node, for a specific class?

I have trouble Googling for this, which tells me it’s not likely to exist :frowning:

I have a custom UObject type defined in C++ which requires complex initialization. I’d like to forbid Blueprints from offering the typical '“Construct Object From Class” in favor of my own function. Or put another way, I’d like the “Construct Object From Class” node to have special behavior for my type: call into a specific function rather than do its default behavior of manually exposing each property as a pin.

Hey - Can you provide more info on what you want to achieve?

IIRC There is no way to override “Construct Object From Class**”** as it is really generic. If I’m understanding you correctly here is what i would do:

  • Firstly, mark your whole class as not blueprintable, so it can be referenced in BP’s but not constructed
  • Secondly, create a custom function that you will use to create your class with while initialization params
UCLASS(NotBlueprintable)
class YOURMODULE_API UMyObject : public UObject
{
    GENERATED_BODY()

public:
    UFUNCTION(BlueprintCallable, Category="MyObject")
    static UMyObject* CreateMyObject(UObject* Outer, int32 InitParam);
};

If you provide more info, mybe I’ll be able to offer you a better solution :slight_smile:

1 Like

if you know the exact class params then just wrap it in a static function.

if however you need advanced functionality its actually the K2Node you need to override and use TSubclassOf to limit you your class

Hi, I’m honestly not sure what else to add about it…it’s an object with a lot of initialization logic, and it’s much nicer to have that logic run in the same BP node that constructs the object so that there’s no way to have a half-initialized instance. I have a static UFUNCTION which does this but the user can still improperly construct an instance using the usual Construct Object From Class node.

like Gawron said this should do the trick?

I thought this prevents subclassing in BP, not construction? I can try it out locally but every resource I find on this mentions the former and not the latter. I do need the ability to subclass it in BP, for the record.

if i understand correctly, imho this seems like a really bad pattern. i think the appropriate thing to do is ensure the initialization happens more sanely. either by the base class, or some other manager.

and ensure that not being initialized doesn’t destroys the universe, which is completely legal.

alternatively you can upgrade it to an actor (without scene root), and have it’s parameters exposed on spawn. maybe you’ll need a bp base for that.

UObjects support expose on spawn too

you might be right ive not tried it myself, essentially you’re trying to block your class from the original construct Node? I wouldnt recommend modifying a engine node so aside from hiding your class from blueprint i’m not sure you can.

it might just be better to log a warning or even crash inside your class if its not intialized

1 Like

Yeah currently I log errors, but always better to make it impossible to use incorrectly :stuck_out_tongue:

What’s weird to me is that Unreal allows custom Make and Break functions for structs, so you can do this for a struct even though structs are meant to be much simpler than Objects.