# GetAllActorsOfClass(): Cannot convert from TArray\<\> to TArray\<\> &

**URL:** <https://forums.unrealengine.com/t/getallactorsofclass-cannot-convert-from-tarray-to-tarray/313978>\
**Category:** C++\
**Tags:** actor, tarray, get-all-actors-from-, unreal-engine, UE4, CPP, question\
**Created:** [April 6, 2015, 1:58am UTC](https://forums.unrealengine.com/t/getallactorsofclass-cannot-convert-from-tarray-to-tarray/313978 "2015-04-06T01:58:04Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![asperatology](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@asperatology](https://forums.unrealengine.com/u/asperatology)\
**Post date:** [April 6, 2015, 1:58am UTC](https://forums.unrealengine.com/t/getallactorsofclass-cannot-convert-from-tarray-to-tarray/313978/1 "2015-04-06T01:58:04Z")

</div>

[I am following the answers from here][1], but I still couldn’t pass in the TArray into UGameplayStatics::GetAllActorsOfClass().

This is how my code looks like:

```
#include "GetDebt.h"
#include "../Player/Machine/BaseFrame.h"
#include "FleeingObstacle.h"

AFleeingObstacle::AFleeingObstacle(const FObjectInitializer& ObjectInitializer) : Super(ObjectInitializer){
	//TTransArray<AActor*> Array = this->GetWorld()->PersistentLevel->Actors;
}

void AFleeingObstacle::BeginPlay(){
	Super::BeginPlay();

	//ERROR CODE
	TArray<ABaseFrame*> BaseFrameArray;
	UGameplayStatics::GetAllActorsOfClass(this->GetWorld(), ABaseFrame::StaticClass(), BaseFrameArray);
	if (BaseFrameArray.Num() > 0){
		LOG("Number of ABaseFrame in the TArray: " + FString::FromInt(BaseFrameArray.Num()));
	}
}

void AFleeingObstacle::Tick(float Delta){
	Super::Tick(Delta);
}

void AFleeingObstacle::Move(){
	LOG("MOVING... AT THE SPEED OF SOUND.")
}

```

and the header file contains the following code:

```
#pragma once

#include "Obstacle/Obstacle.h"
#include "FleeingObstacle.generated.h"

/**
 * 
 */
UCLASS()
class GETDEBT_API AFleeingObstacle : public AObstacle
{
	GENERATED_BODY()
public:
	//PROPERTIES
	

	//FUNCTIONS
	AFleeingObstacle(const FObjectInitializer& ObjectInitializer);

	void BeginPlay() override;

	void Tick(float DeltaSeconds) override;

	void Move() override;
};

```

I am still having this error popping up (Attachment provided):

 ![37508-ue4_error.png](https://d3kjluh73b9h9o.cloudfront.net/original/4X/3/7/0/370fba262aeaff574137be480bd8e5a8db936ebc.png)

What am I doing wrong this time? I am so confused.

---

<div class="post-metadata">

**Author:** ![Duncan\_Dam](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Duncan\_Dam](https://forums.unrealengine.com/u/Duncan_Dam)\
**Post date:** [April 6, 2015, 6:43am UTC](https://forums.unrealengine.com/t/getallactorsofclass-cannot-convert-from-tarray-to-tarray/313978/2 "2015-04-06T06:43:15Z")

</div>

UGameplayStatics::GetAllActorsOfClass will only accept TArray so your TArray BaseFrameArray; must be TArray BaseFrameArray;

Only after this then you can cast to whatever class you want.

---

<div class="post-metadata">

**Author:** ![asperatology](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@asperatology](https://forums.unrealengine.com/u/asperatology)\
**Post date:** [April 6, 2015, 9:18pm UTC](https://forums.unrealengine.com/t/getallactorsofclass-cannot-convert-from-tarray-to-tarray/313978/3 "2015-04-06T21:18:52Z")

</div>

Thank you, but can you please rephrase your answer? I had to re-read your answer numerous times in order for me to understand that you meant:

```
TArray<AActor*> BaseFrameArray;

```

And not:

```
TArray<AActor> BaseFrameArray;

```

Nor:

```
TArray<[INSERT SOME SUBCLASS OF AACTOR]> BaseFrameArray;

```

Nor:

```
TArray<[SAME AS ABOVE] *> BaseFrameArray;

```

Nor:

```
TArray BaseFrameArray;

```

Thank you again. 😃

---

<div class="post-metadata">

**Author:** ![ja0335](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/ja0335/32/560997_2.png) [@ja0335](https://forums.unrealengine.com/u/ja0335)\
**Post date:** [January 21, 2016, 10:51pm UTC](https://forums.unrealengine.com/t/getallactorsofclass-cannot-convert-from-tarray-to-tarray/313978/4 "2016-01-21T22:51:31Z")

</div>

Hi asperatology.

The solucion is simple. UGameplayStatics::GetAllActorsOfClass isn’t a template class so you must pass it an array of AActors\*

Example Code:

```
TArray<AActor*> FoundActors;
UGameplayStatics::GetAllActorsOfClass(GetWorld(), AMyActor::StaticClass(), FoundActors);

for (AMyActor* TActor: FoundActors)
{
	AMyActor* MyActor = Cast<AMyActor*>(TActor);

	if(MyActor != nullptr)
			// Do what ever you need with your MyActor
}
```

---

<div class="post-metadata">

**Author:** ![asperatology](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@asperatology](https://forums.unrealengine.com/u/asperatology)\
**Post date:** [January 21, 2016, 11:16pm UTC](https://forums.unrealengine.com/t/getallactorsofclass-cannot-convert-from-tarray-to-tarray/313978/5 "2016-01-21T23:16:21Z")

</div>

Thanks. That sort of makes sense.

---

<div class="post-metadata">

**Author:** ![Anonymous\_dd56a58405288d59cf93311503aeeb3e](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Anonymous\_dd56a58405288d59cf93311503aeeb3e](https://forums.unrealengine.com/u/Anonymous_dd56a58405288d59cf93311503aeeb3e)\
**Post date:** [May 11, 2016, 4:47am UTC](https://forums.unrealengine.com/t/getallactorsofclass-cannot-convert-from-tarray-to-tarray/313978/6 "2016-05-11T04:47:20Z")

</div>

I also understant what i do can use GetAllActorsOfClass

---

<div class="post-metadata">

**Author:** ![JethroRZ](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@JethroRZ](https://forums.unrealengine.com/u/JethroRZ)\
**Post date:** [May 7, 2019, 9:02am UTC](https://forums.unrealengine.com/t/getallactorsofclass-cannot-convert-from-tarray-to-tarray/313978/7 "2019-05-07T09:02:26Z")

</div>

maybe a bit late, but just in case:

it should be

```
 for (AActor* TActor: FoundActors)
     {
         AMyActor* MyActor = Cast<AMyActor>(TActor);
     
         if(MyActor != nullptr)
                 // Do what ever you need with your MyActor
     }
```
