While this may work, it shouldn’t be this way. You should be able to return a const reference from a function. If the blueprint system then chooses to copy this into a new non-const/ref structure, so be it, the inefficiencies of BP climb.
The problem lies here:
const bool bOutParam = (Property->HasAnyPropertyFlags(CPF_OutParm | CPF_ReturnParm) && !(Property->HasAnyPropertyFlags(CPF_ReferenceParm)));
if ( ((SourcePin->Direction == EGPD_Input) && bOutParam) || ((SourcePin->Direction == EGPD_Output) && !bOutParam))
{
MessageLog.Error(*FString::Printf(*LOCTEXT("DirectionMismatchParameter_Error", "The direction of @@ doesn't match the direction of parameter %s").ToString(), *Property->GetName()), SourcePin);
}
An an out param (i.e. return value) cannot be a reference, const or not, which is entirely silly.