Static(scope) TArrays?

So I’m trying to set up a static TArray of actors for some small testing. I realize that static TArrays can’t be exposed to the blueprint system, so I’m trying to expose simple functions to modify it. My current setup is that I have a static TArray of actors and two simple static functions to add and remove actors from the array. My current setup lookes like this:

Turret.h

UCLASS(Blueprintable)
class TOWERDEFENSE_API ATurret : public AActor
{
	GENERATED_UCLASS_BODY()

	//UPROPERTY()  //This doesn't work...
	static TArray<AActor*> EnemyList;

	UFUNCTION(BlueprintCallable, Category = "Turret_Statics")
	static void AddActorToList(AActor *Actor);

	UFUNCTION(BlueprintCallable, Category = "Turret_Statics")
	static void RemoveActorFromList(AActor *Actor);
};

Turret.cpp

ATurret::ATurret(const class FPostConstructInitializeProperties& PCIP)
: Super(PCIP)
{
	PrimaryActorTick.bCanEverTick = true;
}

void ATurret::AddActorToList(AActor *Actor){
	ATurret::EnemyList.Add(Actor);
}

void ATurret::RemoveActorFromList(AActor *Actor){
	ATurret::EnemyList.Remove(Actor);
}

But there are many problems I’m running into.

First, I guess static TArrays can’t be a Uproperty because it gives me the error 'Unrecognized type ‘static’ '. It compiles fine without either the UProperty or the static keyword.

Secondly, I can reference the static TArray inside the static functions but I can’t perform any operations on them, such as Add or Remove. The error it gives me is

Error 1 error LNK2001: unresolved external symbol "public: static class TArray<class AActor *,class FDefaultAllocator> ATurret::EnemyList" (?EnemyList@ATurret@@2V?$TArray@PEAVAActor@@VFDefaultAllocator@@@@A)

Which I have no clue what that’s trying to tell me. My ultimate objective here is to have a very simple static list to hold all the enemy actors in the game for my turret class to reference. I put the list in the turret class hoping to just run some simple tests without creating more classes.

Any help would be great!

Hi,

You are correct in that static UProperties are not supported.

Your other problem is a general C++ issue, where static members are only a declaration, but you haven’t defined it outside the class:

http://www.parashift.com/c++-faq/link-errs-static-data-mems.html

In your case, you’ll need this in your Turret.cpp file:

TArray<AActor*> ATurret::EnemyList;

Steve

Perfect! Guess I should have done more searching around about general c++ static variables. Thanks!