Hey guys!
I’d like to update a TArray with the right number of UInstancedStaticMeshComponent when I change a value in the details panel.
For now, I can get the TArray to be initialized with the expected number of components when we look at the default values assigned to variables in the header. But then, when I change the values of those same variables in the editor, the TArray of components is not updated accordingly. Here is some code:
in the header:
private:
UPROPERTY(VisibleAnywhere, Category = "Instanced Mesh")
TArray<UInstancedStaticMeshComponent*> GridMeshChunks;
public: UPROPERTY(EditAnywhere, Category = "Grid Properties", meta = (ClampMin = "1", ClampMax = "10", UIMin = "1", UIMax = "10"))
int gridLength = 2;
UPROPERTY(EditAnywhere, Category = "Grid Properties", meta = (ClampMin = "1", ClampMax = "10", UIMin = "1", UIMax = "10"))
int gridWidth = 2;
UPROPERTY(EditAnywhere, Category = "Grid Properties", meta = (ClampMin = "1", ClampMax = "10", UIMin = "1", UIMax = "10"))
int gridHeight = 2;
in the .cpp
AGridManager::AGridManager()
{
PrimaryActorTick.bCanEverTick = true;
bReplicates = true;
bAlwaysRelevant = true;
int chunkNum = gridLength*gridWidth*gridHeight;
GridMeshChunks.Empty();
for (int i = 0; i < chunkNum; i++)
{
FString name = "GridMesh" + FString::FromInt(i);
GridMeshChunks.Add(CreateDefaultSubobject<UInstancedStaticMeshComponent>(*FString(name)));
}
RootComponent = GridMeshChunks[0];
for (int i = 1; i < chunkNum; i++)
{
GridMeshChunks[i]->SetupAttachment(RootComponent);
}
}
So, in this case, I obtain an array with 8 UInstancedStaticMeshComponents. Nothing happens when I change the value in-editor. I believe for something to happen I’d need to add something to the OnConstruction script. I tried to create the components similarly in that function but I couldn’t find a way to make it work without crashes. Any pointers or tips?