How to create custom blueprint pure function with target input ?

Hello, I am having troubles making my custom BlueprintPure function with Target input. Every default node has Target input which is not even parameter of C++ function so it is somehow added by some hidden blueprint logic. Do you know how can I create custom node with target input ? I tried really many combinations with const/static/type&/meta and so on. I know that I can make my node static and then use custom UObject* parameter however I would like to utilize default Target parameter.


Thank you :))

The target pin you’re seeing is in essence the this pointer.

So in C++ terms when you call a function on an instance of an object you can do GetOwner() (which implies this->GetOwner()) or MyActor->GetOwner(). And once you’re inside that function this is implicitly the context of the function. The same is roughly true in blueprints. The target pin is the context of the function. By default, as in your picture, you see it defaults to self (which is the same as this in C++) thus your GetOwner() or this->GetOwner(), but you can also wire in a context to get your MyActor->GetOwner().

So, to answer your question, the target pin is going to be automatically created for you when you define a function inside a class. However, if you’re using the static functions in a blueprint function library, then you need to provide the context yourself. So your function implementation (if you were trying to imitate the GetOwner() case but declared outside of AActor()) would be (roughly)

UFUNCTION(BlueprintPure, Category=“Actor”, meta=(DefaultToSelf=Target))
AActor* GetOwner(AActor* Target);

Thank you for your reply and explanation Marc,

I know what is target and what it is for :slight_smile: but… Nevermind, I solved it. Your solution use custom parameter for Target but I wanted to know how to get that automatically generated Target pin.

BP function needs to be **BlueprintCallable **and const. If I combine these two things then I get BlueprintPure function with autogenerated Target pin. Otherwise I will end up with function without Target pin like on picture above.

UFUNCTION(BlueprintCallable, Category = "Camera Bounds")
FVector GetClosestPointToB(FVector Point) const;

FVector ACustomActor::GetClosestPointToB(FVector Point) const

It will be nice to see some documentation on these things :slight_smile:

Using const works, but I’m no longer able to access non-constant functions in the parent class from within my blueprintpure function. To elaborate, in my case I have an engine function in the parent class that is not available from Blueprints and I want to expose that from a subclass using a BlueprintPure wrapper function for easy access.

I tried Marc’s suggestion (add a Target variable) but with this approach dragging a wire off my class only lists the blueprintcallable functions of my class, not the pure ones, so I have to turn ‘context sensitive’ off, select the node from the master list of functions and then wire it up to ‘Target’. I’m using this method for now to move ahead with my work, but unless I’m missing something not being able to contextually call the pure functions off (an appropriate) pin feels like a drawback.

Edit: Actually the need to explicitly include a parameter ‘Target’ is no longer an issue - as soon I turn ‘context sensitive’ off and pick the right node it automatically latches onto a target node. (so I actually end up with two target nodes - one being the target node that UE automatically created when I dragged a wire and the second being the Target node that I added explicitly). So the only issue I see at this point is the need to turn context sensitive off to access blueprintpure functions.