Creating node returning object of given class.

Is there any tutorial how to create a node that would return object of the class I would specify for it, so I don’t have to cast it? Something that would work like ConstructObjectFromClass except, I want to code some custom logic instead of creating new object. From what I found so far I guess K2Node class is something to look into. I looked into actual K2Node_ConstructObjectFromClass, but there are barely any comments and I like knowing what I am doing. I know how to create K2 node that appears in the graph, so that’s not an issue. I am rather asking for help regarding that output thing.

To change the return type of the function, those nodes do something like this:

UEdGraphPin* ResultPin = GetResultPin();
ResultPin->PinType.PinSubCategoryObject = InClass->GetAuthoritativeClass();

They usually do that once the “Class” input pin has changed and it’s value is valid.