How to create a TArray of Interface pointers?

I can’t seem to declare an array of Interfactes. It can be done in blueprints so I assume there is a way to do it in C++

I’ve tried:

UFUNCTION(BlueprintCallable, Category = "Cell Tile")
TArray<TScriptInterface<IDamageableEntity>> GetAllEntitiesInDirection(int _Count, EMoveDirection _TileToMoveTo);

which gives a link errror:

error LNK2019: unresolved external
symbol “public: class TArray TScriptInterface IDamageableEntity>,class
FDefaultAllocator> __cdecl
ACellTile::GetAllEntitiesInDirection(int,enum
EMoveDirection)”
(?GetAllEntitiesInDirection@ACellTile@@QEAA?AV?$TArray@V?$TScriptInterface@VIDamageableEntity@@@@VFDefaultAllocator@@@@HW4EMoveDirection@@@Z)
referenced in function "void __cdecl
dynamic initializer for 'Z_CompiledInDeferEnum_UEnum_ECellTypeResourceID''(void)" (??__EZ_CompiledInDeferEnum_UEnum_ECellTypeResourceID@@YAXXZ)

And I’ve tried

UFUNCTION(BlueprintCallable, Category = "Cell Tile")
TArray<IDamageableEntity*> GetAllDamageablesInDirection(int _Count, EMoveDirection _TileToMoveTo);

which gives this error:

error C2679: binary ‘=’: no operator
found which takes a right-hand operand
of type ‘TArray *,FDefaultAllocator>’ (or there is no acceptable conversion) note: could be
‘TArray,FDefaultAllocator>
&TArray,FDefaultAllocator>::operator
=(TArray,FDefaultAllocator>
&&)’

I’ve made sure I’m #including “Runtime/CoreUObject/Public/UObject/ScriptInterface.h”

What’s the correct way to declare an Array of interface pointers?

Not sure, but perhaps this might help:
TMap with USoundWave not possible?

If you’re unable to return the value, you can make it the first out parameter, which is how BPs do it.

Below should work:

// .h
UFUNCTION(BlueprintCallable, Category = "Cell Tile")
void GetAllEntitiesInDirection(int _Count, EMoveDirection _TileToMoveTo, /*out*/ TArray<TScriptInterface<IDamageableEntity>>& Entities);

// .cpp
void MyClass::GetAllEntitiesInDirection(int _Count, EMoveDirection _TileToMoveTo,/*out*/ TArray<TScriptInterface<IDamageableEntity>>& Entities)
{
	TArray<TScriptInterface<IDamageableEntity>> entities = TArray<TScriptInterface<IDamageableEntity>> ();
	
	// Populate array
	
	Entities = entities;
}

I think it didn’t like that I was trying to use an Interface in a Templated function, but the templated function does work using your method above. It’s a bit strange but this seems to be a good enough work around

Thanks!