So I recently got my code to compile when I had a single blueprint template for the fences I wanted to spawn from my spawner object blueprint. Now, I’m trying to expand that into a set of multiple possible templates. The idea is that when I want to spawn a fence, I can choose from one of eight different templates (representing fences of different heights) whether at random or by some other logic. Really, the only difference between the fence blueprints is their static meshes.
At present, my code looks like this:
ObstacleSpawner.h
//Create a template to allow for multiple blueprints of fence objects to track
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Fence")
TSubclassOf<class AFenceObstacle> FenceTemplate[8];
ObstacleSpawner.cpp (Tick)
//Increment/Decrement timers, spawn objects
if (SpawnTimer <= 0.0f) {
//Spawn a new fence obstacle with appropriate height
int FenceHeight = FMath::RandRange(0, 7);
if (FenceTemplate[FenceHeight]) {
AFenceObstacle* NewFence = World->SpawnActor<AFenceObstacle>(FenceTemplate[FenceHeight]);
FVector SpawnLocation = FVector(1000.0f, 0.0f, 0.0f);
NewFence->SetActorLocation(SpawnLocation);
NewFence->ObstacleSpeed = ObstacleSpeed;
Fences.Add(NewFence);
} else {
//DEBUG
GEngine->AddOnScreenDebugMessage(-1, 5.0f, FColor::Red, "Spawning new fence FAILED because FenceTemplate is not defined.");
}
SpawnTimer = 5.0f; //<-- This will be modified later to depend on TimeElapsed
}
When I try to compile, I get this error message in my Output tab:
Error: Static array cannot be exposed to blueprint ObstacleSpawner.FenceTemplate
Suggestions?


