# TArray of ANY Actors as function parameter

**URL:** <https://forums.unrealengine.com/t/tarray-of-any-actors-as-function-parameter/485175>\
**Category:** Programming & Scripting\
**Tags:** unreal-engine\
**Created:** [June 21, 2021, 5:25pm UTC](https://forums.unrealengine.com/t/tarray-of-any-actors-as-function-parameter/485175 "2021-06-21T17:25:48Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Willidan](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Willidan](https://forums.unrealengine.com/u/Willidan)\
**Post date:** [June 21, 2021, 5:25pm UTC](https://forums.unrealengine.com/t/tarray-of-any-actors-as-function-parameter/485175/1 "2021-06-21T17:25:48Z")

</div>

Hi!

I created prototype version of my spawning function in blueprints. It takes unit class, number of units to spawn and a reference to an Array of Actors as parameters. I can pass any Array that holds object references of any class that is a child of Actor. I can then modify that Array inside my function.

 ![341965-spawnunits.png](https://d3kjluh73b9h9o.cloudfront.net/original/4X/7/d/8/7d8aa125099f9e489a31edea5cbe7b4fb286bebf.png)

Now I’m trying to rewrite this function with C++. Using `TArray<AActor*>&` as parameter in function declaration does not let me use anything but `TArray` of `AActor`.

```
	UFUNCTION()
	void SpawnUnits(TSubclassOf<AActor> UnitClass, int Number, TArray<AActor*>& UnitArray);

```

I’m trying to achieve similar functionality as in blueprints version so that I could pass any `TArray` of objects that are children of `AActor`. Is there any way to do so? As for now IDE gives me this error:

 ![341966-call.png](https://d3kjluh73b9h9o.cloudfront.net/original/4X/0/4/8/0483feaca41ec47fb9db6c09b6d27ec89756f709.png)

---

<div class="post-metadata">

**Author:** ![Willidan](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Willidan](https://forums.unrealengine.com/u/Willidan)\
**Post date:** [June 22, 2021, 11:07am UTC](https://forums.unrealengine.com/t/tarray-of-any-actors-as-function-parameter/485175/2 "2021-06-22T11:07:26Z")

</div>

Found the answer in nativized Blueprint code.

When calling with Array of different type, BP uses something called TArrayCaster:

```
bpf __SpawnUnits__ pf(bpv __PopulationUnitClass__ pf, bpv __PopulationNumber__ pf, /*out*/ TArrayCaster<ABP_Animal_Rabbit_C__pf1010915279*>(bpv__PopulationUnits__pf).Get<AActor*>());

```

So to get it working, call to SpawnUnits shoud look like:

```
SpawnUnits(PopulationUnitClass, PopulationNumber, TArrayCaster<AAnimal_Rabbit*>(PopulationUnits).Get<AActor*>());
```
