TArray of ANY Actors as function parameter

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.

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:

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*>());