[HowTo?] CreatePin with value from code

If the return value is from a C++ function you may want to expose it as an UFunction and to use UK2Node_CallFunction. There is an example in UK2Node_EaseFunction::ExpandNode which calles a function and sets the return value to a result pin.

I’ve made a custom node and I would like to create an output pin with a value that I have from in code rather than in BP.

It shouldn’t matter, but the nodes resembles the input options nodes and the value is different per node; hence my requirement.

Right now I think I can use u2k_CallFunction node with a lambda function that will return the value I have, but it sounds a bit weird doing so.

From looking at the source code I think it can be done using Context.NetMap / FBPTerminal, but i’m not entirely sure what they are or how they use them (couldn’t find anything on google either).

Don’t know if it matters, but the code is running from the ExpandNode() method in my UK2Node class

I’m aware and I know I can use it, but this is not the case;
the node it self has a member variable (a field) which has the value.
The only way I’ll be able to use UK2Node_CallFunction, is if I can use it with a lambda function, which I believe you can’t.

You could provide the value using a UFunction of the node itself and then rewire it to the output pin. Something like:

// Find our UFunction, <UClass> would be where you ufunction is declared, so it might be the class of your node
UFunction* Function = <UClass>::StaticClass()->FindFunctionByName(*MyFunctionName);

// The call function does all the real work,m we use it to call an UFunction within our expanded node
UK2Node_CallFunction* CallFunction = CompilerContext.SpawnIntermediateNode<UK2Node_CallFunction>(this, SourceGraph);

// Setting up the function and create a new node in the graph with it
CompilerContext.MessageLog.NotifyIntermediateObjectCreation(CallFunction, this);

// Move the functions return pin to our Result pin, pins must be matching type or use wirldcard pins
CompilerContext.MovePinLinksToIntermediate(*FindPin(TEXT("Result")), *CallFunction->GetReturnValuePin());

// Break links to our own node

This would be in your ExpandNode method. I just followed what works in https://github.com/EpicGames/UnrealEngine/blob/release/Engine/Source/Editor/BlueprintGraph/Private/K2Node_EaseFunction.cpp, adapting the idea a bit to route the return pin of a function which provides a value to the result pin of the node.

You forgot to use the Function variable with CallFunction … ?
That is, how would you use the CallFunction node to set a function on the UK2Node class (hence your Function variable)

Yes I omitted parts (should have put a bracket I guess xD)

But you omitted the part that will actually make it work… as far as I know, there is no way to assign a UFunction to UK2Node_CallFunction. the code has no value without that part…

Hope it’s clearer now ^^

I’m afraid not; now you’re doing what I said I can do from the beginning, you’re using a static function on another class. Remember, I have a local variable which I need to pass to it, so using a static method of another class I can’t pass the local variable to it.

There is functions already prepared for you existing in standard bp library called MakeLiteral~Something~
Here is an example of them usage [UE_4.17\Engine\Source\Editor\BlueprintGraph\Private\K2Node_GetNumEnumEntries.cpp]

	const FName FunctionName = GET_FUNCTION_NAME_CHECKED(UKismetSystemLibrary, MakeLiteralInt);
	UK2Node_CallFunction* MakeLiteralInt = CompilerContext.SpawnIntermediateNode<UK2Node_CallFunction>(this, SourceGraph); 

	UEdGraphPin* OrgReturnPin = FindPinChecked(Schema->PN_ReturnValue);
	UEdGraphPin* NewReturnPin = MakeLiteralInt->GetReturnValuePin();
	check(NULL != NewReturnPin);
	CompilerContext.MovePinLinksToIntermediate(*OrgReturnPin, *NewReturnPin);

	UEdGraphPin* InputPin = MakeLiteralInt->FindPinChecked(TEXT("Value"));
	check(EGPD_Input == InputPin->Direction);
	const FString DefaultValue = FString::FromInt(Enum->NumEnums() - 1);
	InputPin->DefaultValue = DefaultValue;

I’m using the static class of your node to find the UFunction with name MyFunctionName which is the function you will wire-up. MyFunctionName would provide the variable.