C++ Error C2679: Binary '=': no operator found which takes right-hand operand of type 'TArray'

#Pass by Reference

This would go a lot smoother if you pass the array by reference like this:

//void return type, pass array by reference
void ARTSHUD::GetAllUnitsOfType(Faction, Type, TArray<UClass*>& returnArray)
{
  //current code, but remove the local variable called returnArray
}

now to use it:

  TArray Result;
    GetAllUnitsOfType(EFaction(Faction),EUnitType(Type), Result);

Not sure how you are using your macro but if you are declaring Result somewhere before you use your macro then you dont have to include it in the macro.

#Performance

This setup will have performance benefits for you!

Look up “C++ Return array by reference” to see why.

#Big Picture, Templates

It seems based on your function name that you really want a template function

I suggest template function + GetAllActorsOfClass

I have wikis on both of these subjects.

A new, community-hosted Unreal Engine Wiki - Announcements - Unreal Engine ForumsObject%26_Actor_Iterators,_Optional_Class_Scope_For_Faster_Search

My solution is based on you wanting to find runtime instances of your units, not entirely sure if that’s your goal or not, if not, then the pass by ref solution should help you :slight_smile:

Enjoy!

Rama