Sorting TArray with polymorphic objects

my idea was that I was going to hold objects in a

TArray<TObjectPtr<UInteractableComponentBase>> Interactables;

and for baseline sorting I gave it a public property of
int32 PriorityValue

supposedly I could define

virtual bool UInteractableComponentBase::operator<(const UInteractableComponentBase& Other) const
{
    return PriorityValue < Other.PriorityValue;
}

then in the derived classes I could override the “operator<” to use a cast to check against say an ItemID member value of the derived class.
but UBT throws an error about needing to define a predicate, where from what I understand a predicate would mean that I would need to effectively create a sort function to take account of everything at once?

Best I can work out is just giving a 2nd and/or 3rd member to the UInteractableComonentBase then purposefully assigning those members in the derived class then in the base class defining a

static bool SortPredicate(const UInteractableComponentBase& LHS, const UInteractableComponentBase& RHS)
{
    // sorting logic, if function returns true LHS will be a lower index then RHS
    // int and int like things are best especially if list might be big
}

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.