A few times a year, I run into this issue and never find a solution online. Here’s the latest use case:
I have an interface function that returns an array of other interfaces as an out parameter pointer (the use case is unimportant, it’s simply to contextualise the question). Storing a reference to and modifying that array elsewhere has got me stumped! I’d want to modify that collection from objects other than the one implementing the interface. From what I understand you return a pointer to the array and can then modify the collection. Compiling that solution seems okay but breakpointing through the logic shows that the local pointer is a copy of the out parameter and not the collection referenced within the implementing object.
Am I missing something insanely obvious and thus it’s not documented online? Admittedly I’m pretty new to C++ but coming from a C# background I’d assume this should be trivial.
Simplified and condensed code below:
// Executive implementing object:
bool UPinventorySubsystem::TryGetAssociates_Implementation(TArray<TScriptInterface<IAssociate>>& AssociatesOut)
{
AssociatesOut = Associates;
return true;
}
bool UPinventorySubsystem::AddAssociate_Implementation(const TScriptInterface<IAssociate>& Associate)
{
const TScriptInterface<IExecutive> Referencer = TScriptInterface<IExecutive>(this);
return UAssociateLibrary::TryAddAssociateTo(Associate, Referencer));
}
// UAssociateLibrary
bool UAssociateLibrary::TryAddAssociateTo(const TScriptInterface<IAssociate>& Associate,
const TScriptInterface<IExecutive>& Executive)
{
TArray<TScriptInterface<IAssociate>> Associates;
Executive->Execute_TryGetAssociates(Executive.GetObject, Associates);
Associates.Add(Associate);
return true;
}