How can I get my function on the left to have the same “Target [self]” pin as the one on the right?
looking for this, myself.
From what I can tell:
for C++ defined functions: use UFUNCTION metadata ‘DefaultToSelf = <paramname>’
and it looks like you can set only one parameter per function to use this feature.
Sadly, I don’t see any path to using this in a blueprint-only implementation that doesn’t require engine changes. That being said, I don’t think it would be difficult. Something like, in UEdGraphSchema_K2::TrySetDefaultValue - compare with the meta keyword before doing the package lookup.
Alternately, exposing various other of the meta functionality to functions in the advanced interface would be nice.
I am guessing here, but can’t you just put the right one into a variable and read it from there to the left one?
This fitted for my needs, may it helps you:
UFUNCTION(BlueprintCallable,
BlueprintPure, meta=(HidePin =
“WorldContextObject”, DefaultToSelf =
“WorldContextObject”)) static
AQuestManager* GetQuestManager(const
UObject* WorldContextObject);
yes. This is works. Here my own example.
UFUNCTION(BlueprintCallable,
meta = (HidePin = "WorldContextObject", DefaultToSelf = "WorldContextObject")
)
static void TestDefaultToSelf(UObject* WorldContextObject) {
UE_LOG(LogTemp, Warning, TEXT("[WC object] name = %s"), *(WorldContextObject->GetName()))
AActor* Actor = Cast<AActor>(WorldContextObject);
if (Actor != nullptr) {
UE_LOG(LogTemp, Warning, TEXT("[WC object] is AActor"))
}
}
It will create bp node TestDefaultToSelf
with one hidden pin.
I called it in BP_ThirdPersonCharacter this way:
And got this results:
Now WorldContextObject
became refrence to bp actor that calls it.
Hope it helps someone.
This is a bit old but for future reference:
For creating the node, the code below could be an example
UEdGraphPin* UK2Node_MyNode::TryCreateSelfPin()
{
// Check if the blueprint qualifies for self
UEdGraphPin* TargetPin = nullptr;
auto bp = GetBlueprint()->GeneratedClass;
auto bpgc = Cast<UBlueprintGeneratedClass>(bp.Get());
auto defObj = bpgc->ClassDefaultObject;
if (!defObj->IsA<UMyDesiredTypeForSelf>())
return TargetPin;
// Create a self pin
TargetPin = CreatePin(EGPD_Input, UEdGraphSchema_K2::PC_Object, defObj->GetClass(), UEdGraphSchema_K2::PN_Self);
TargetPin->PinFriendlyName = FText::FromName(FName("This is a self pin"));
return TargetPin;
}
And to implement it in ExpandNode, you could utilize a K2Node_Self as IntermediateNode
connect its output pin.