How to use mouse click to change current pawn under control?

Actor iterating is very expensive, you only really want to do it during a BeginPlay() or similar. This is because most things you place in the world are based off AActor, so a typical map has thousands of actors.

In the case of an RTS, where most units are spawned dynamically, I would create a pointer TArray<APawn> per player of their units at map start, and then every time you spawn a unit, add it to this list of pointers. This way you have your dynamic list of pawns of only units, and never have to iterate through the world. TArray also has some very nice features for iterating through the array quickly.

This would leave you with a TArray of 100 units, and one TArray per player. Since each of the indexes of the array is a pointer to a pawn, you should have all base functionality as if each one was the pawn, so you can do all of your AI logic, Movement, and other things using a base PlayerUnits[index]-> call.

More info on TArrays and Dynamic Arrays in general is here: