I am attempting to acquire a set of actors in a volume using GetOverlappingActors, filter them based on whether they implement an interface (since I know I can do it in Blueprints since I’ve done so previously), and cast the AActor * variable back to a TScriptInterface variable after retrieval.
So far my code looks like this…
TArray<AActor*> TargetableActors;
TargetingVolume->GetOverlappingActors(TargetableActors, UTargetable::StaticClass());
if (GetIsTargeting()) {
// Find the position of the current target
int32 CurrentPosition = TargetableActors.Find(Cast<AActor>(MyTarget.GetObjectW()));
int32 NextPosition = (CurrentPosition + 1 + OppositeDirection*(-2)) % TargetableActors.Num();
SetTarget(Cast<ITargetable>(TargetableActors[NextPosition]));
}
I’m receiving an error for the SetTarget line that says that I cannot convert argument 1 from ‘ITargetable’ pointer to 'UObject ’ pointer. Any ideas on how to fix this? I’ve tried various combinations of _getUObject(), TScriptInterface(TargetableActors[NextPosition]) - (as type ITargetable), and even casting to UTargetable instead.
Note: SetTarget accepts a TScriptInterface type with ITargetable as the type parameter and subsequently assigns that type to the same type of variable.