Whats the best way to set K2node Pin default values?

currently i’m doing this

FString DefaultValue;
	FMyStruct::StaticStruct()->ExportText(
		DefaultValue,
		&NodeValue,
		nullptr,
		nullptr,
		PPF_None,
		nullptr);
Schema->SetPinAutogeneratedDefaultValue(Pin, DefaultValue);

which feels very fragile especially on structs/maps etc

If I were doing this I wouldn’t attempt to set the default value at all.

Instead I would use the K2Node_MakeStruct to actually construct an instance and connect that to the input pin.

Or failing that for some reason (MakeStruct might not be easily usable from another module’s code), using a CallFunction node that returns an instance of the struct. Basically doing an end-run around MakeStruct to call the NativeMake function directly.

i thought about that but at some point i still have to set the defaults on the pin from an FString. i thought there might be a better way like copying memory directly

I don’t follow. Why would you still have to set the defaults using a string?

it seems thats just how defaults are set and serialized

but to be clear im trying to copy a property from the k2node itself as a function param on the call function node. Since the k2node doesnt exist at runtime on expand node i copy it to the default value of the input pin

If you want to use the inline defaults, but sometimes (like this case) that’s more difficult than is worth it.

Ah, yeah that’s tricky. I’ve done that with engine structures that have their own ToString functions. Doing the export text call seems like the most generic approach. You’re worried about maps or structs in the FMyStruct? or something else? One way to check would be see what happens if you add an FMyStruct to a DevSettings or UserSettings so that it’s written to an ini. I know maps/structs worth there just fine. There are various things that won’t work very well exported to text.

Also, SetPinAutogeneratedDefaultValue is more for the blueprint UX. You can just set Pin->DefaultValue to what you get back from ExportText (or directly pass it in for the function’s out parameter). Or are you actually trying to do this during AllocateDefaultPins? Are you trying to default the structure pins to something different than the default values of the structure normally?

Maybe it’s worth not having the structure pin at all, and using reflection to make actual pins for each of the properties instead. Sort of like the ExposeOnSpawn pins when creating a UObject.

its on expand node and to be fair it does work it just ‘seems’ fragile

but yeah the pin is on a callfunc node which i dont expose.

im using FMemberReference as a property picker on the k2node but just convert it to an FName and pass it though to the callfunc node

yeah this is probably the safest way but since the struct is working ill leave it for now.

for any one else who does something similiar i can say nested structs dont work, i havent tried just a TMap yet.

FString DefaultValueString;
	FMyStruct::StaticStruct()->ExportText(
		DefaultValueString,
		&NodeValue,
		nullptr,
		nullptr,
		PPF_None,
		nullptr);
Pin->DefaultValue = DefaultValueString;

just marking this as solved, seems all pins serialize string values so that’s the best and only way

Well, not all. That’s why DefaultTextValue and DefaultObject are also available. But yeah, anything not those generally supports a conversion to string in one way or another.

good point, i have a love/hate relationship with k2nodes but i guess they’re be removed with BP in the future anyway :frowning: