How should I code an array of units for RTS type game

I’m building a tower defense game, and I want to build an array to hold my pawns which I can spawn and control during the game.

I’m trying to build an array that holds all of my towers so I can just go to my array whenever I need to spawn a tower.

I have a class deriving from the APawn class called ATower, and I have my actual towers inheriting from the ATower class.

I have this array set up:

.h:

TArray TowerArray;

Then in my constructor: (.cpp)

//ATower_Archer is a class derived from ATower

ATower_Archer* archer = Cast(//what to put here);

Then I want to add this reference into an array:

TowerArray.Add(archer);

Also if anyone has any tips on a better way to do this feel free to help me out. You can probably tell I have no clue what I’m doing.

2nd code should not be in costructur, no game object will exist at point when it executed. Constructor should comtain only defaults, initiation and grabing any objects from level should be in BeginPlay()

You should make array of ATowers, ATower should have common virtual functions for all towers which towers would implement by overriding them, this way you will be able to control all towers types just using ATower* type.

But how would I do that?

I have a class inheriting from ATower called ArcherTower.

How would I get an instance of AArcherTower?

I tried ATower* archer = Cast(PController->GetPawn());

but that just crashes my editor