как мне в пин функции передать мою структуру fpathtoscenario?
void UCustomK2Node::ExpandNode(FKismetCompilerContext& CompilerContext, UEdGraph* SourceGraph)
{
Super::ExpandNode(CompilerContext, SourceGraph);
To pass your fpathtoscenario structure into the function pin within your ExpandNode method, you'll need to work with the pins on both your custom node and the function call node. Here's how you can achieve this:
Ensure Your Function Accepts the Structure: First, make sure that the function you're calling (GetScen in this case) has a parameter that accepts your fpathtoscenario structure. For example:
Find the Corresponding Pins: In your ExpandNode method, after allocating the default pins for the function call node, find the pin that corresponds to your structure parameter.
Connect the Pins: If both pins are valid, you can move the links from your node's input pin to the function call node's pin. This effectively passes the structure from your node into the function.
cpp
if (MyStructPin && InStructPin)
{
CompilerContext.MovePinLinksToIntermediate(*MyStructPin, *InStructPin);
}
else
{
// Handle the error: pins not found or invalid
CompilerContext.MessageLog.Error(*LOCTEXT("PinError", "Failed to find the necessary pins for structure passing.").ToString(), this);
BreakAllNodeLinks();
return;
}
Set Default Value (Optional): If you have a default value for the structure and you're not using an input pin, you can set the default value of the function call node's pin. You'll need to serialize your structure to a string format that Unreal Engine understands (typically JSON or a property string).
cpp
if (InStructPin)
{
FString DefaultValue;
// Serialize your fpathtoscenario instance to a string
// For example, using FBlueprintEditorUtils::PropertyValueToString_Direct or similar
// DefaultValue = SerializeYourStructToString(fpathtoscenarioInstance);
InStructPin->DefaultValue = DefaultValue;
}
Finalize the Node Expansion: Finally, make sure to wire up the execution pins and any other necessary pins to ensure the node behaves correctly in the expanded graph.
cpp
// Wire the execution pins
CompilerContext.MovePinLinksToIntermediate(*ExecPin, *CallFunctionNode->GetExecPin());
CompilerContext.MovePinLinksToIntermediate(*ThenPin, *CallFunctionNode->GetThenPin());
// Connect any output pins as needed
UEdGraphPin* FunctionOutputPin = CallFunctionNode->FindPin(TEXT("ReturnValue"));
if (FunctionOutputPin && OutputPin)
{
CompilerContext.MovePinLinksToIntermediate(*OutputPin, *FunctionOutputPin);
}
// Remove the original node
BreakAllNodeLinks();
Note on Struct Serialization: Setting a default value for a struct pin can be complex because you need to serialize the struct into a string that Unreal Engine can parse at compile time. If your struct is not too complex, you might be able to manually construct this string, but for more complex structs, consider using Unreal's property system functions to serialize the struct properly.
Summary: To pass your fpathtoscenario structure into the function pin:
Find the relevant pins on both your custom node and the function call node.
Move the pin links from your node's input pin to the function call node's input pin for the structure.
Set a default value for the function call node's pin if you're not using an input pin.
Handle execution flow by connecting the execution pins appropriately.
Serialize the struct if you're setting a default value directly.
By following these steps, you'll successfully pass your structure into the function pin within the expanded node in the Unreal Engine's Kismet compiler context.