So I’ve finally created a grid that can generate dynamically in the editor. I’ve got two main classes:
- AGridBase → Which is only an AActor with StaticMesh (plane) with a collision box , representing each block of the grid
- GridGenerator → The object that I spawn to generate grid bases.
The code currently works as expected with one minor issue. Whenever I spawn the grid, I get two grids like attached screenshot:
I use the onConstruct class like below:
void APlaneGenerators::OnConstruction(const FTransform& Transform)
{
//Calculate the start and end position of the Grid
InitializeParameters(Transform);
int32 x = floor(xLength / xSizePlane);
int32 y = floor(yLength / ySizePlane);
NoPlanes = x * y; //Total number of grids
//Clear Existing Grid
myGrids = this->Children;
for (AActor* actor : myGrids) {
if (!actor)
{
return;
}
actor->Destroy();
}
//Start spawning grids x*y amount
for (int32 i = 1; i <= x; i++) {
for (int32 j=1; j<=y; j++)
{
SpawnGridBlock(i,j);
}
}
}
Also when constructing the grids:
UWorld* world = GetWorld();
if (world) {
FActorSpawnParameters spawnParams;
spawnParams.Owner = this;
ABaseGrid* tempActor;
tempActor = world->SpawnActor<ABaseGrid>(ActorLocation, GetActorRotation(), spawnParams);
if (tempActor)
{
tempActor->boxCollision->SetBoxExtent(FVector::FVector(xSizePlane / 2, ySizePlane / 2, 1), false);
tempActor->baseGrid->SetRelativeScale3D(FVector::FVector(xSizePlane / 100, ySizePlane / 100, 1));
}
}
Edit: Seems like it runs when I start dragging it, and also when i let go of the mouse.