Having Trouble with TArray Append Function

I’m attempting to append an array of actor objects to another array of actor objects. I’m using the second array to build a list of actors to ignore for collision checks. There must be something I’m missing, either about the append function itself, or assigning arrays of actors, but I cannot figure out what it could be.

Here’s the code I’m using.

In the class declaration

// Array of Triggers in the level
TArray<AActor*> TriggersInLevel;

In the On Begin Play function

// Get all the triggers in the level so that they may be referenced.
UGameplayStatics::GetAllActorsOfClass(GetWorld(), ATriggerBox::StaticClass(), TriggersInLevel);

In the collision check function

TArray<AActor*> ActorsToIgnore;
ActorsToIgnore.Append(TriggersInLevel, TriggersInLevel.Num() - 1);

The error I’m getting on the append is

no instance of overloaded function matches the argument list   argument types are: (TArray<AActor *, FDefaultAllocator>, int)
object type is: TArray<AActor *, FDefaultAllocator>

The collision check function is neither static, nor constant, so I can see no reason this won’t work. Also, directly assigning the ‘Triggers in level’ array to the ‘Actors to ignore’ array works just fine.

This works, append does not.

TArray<AActor*> ActorsToIgnore = TriggersInLevel;

I’d like to append because the ignored actors array is likely to contain other actors as needed. Any help on this would be appreciated, thanks.

After some testing I attempted to just use append to assign the array instead of the raw data and that works, so to clarify.

This works,

TArray<AActor*> ActorsToIgnore;

but this doesn’t.

TArray<AActor*> ActorsToIgnore;
ActorsToIgnore.Append(TriggersInLevel, TriggersInLevel.Num() - 1);

I’m still unsure why this would be. Would be appreciative of an explanation, just so I can better understand what’s happening in the engine code.


TArray has several overloads for the Append() function, and your code is calling an invalid one. You don’t pass in the number of items to append, so just do it like so:


You are currently calling the third function shown here, which takes a pointer to an element type, not another TArray().