Cześć. Napisałem takie o to makro:
#define SPAWN_CHUNK_WITH_PARAMS(chunkReference, bonusXLocation, bonusYLocation, bonusX, bonusY) \
chunkReference = Cast<AWorldGenerator>(UGameplayStatics::BeginDeferredActorSpawnFromClass(this, AWorldGenerator::StaticClass(), FTransform(FRotator(0, 0, 0), FVector(spawnedChunks[xMap.first][yMap.first]->GetActorLocation().X + bonusXLocation, spawnedChunks[xMap.first][yMap.first]->GetActorLocation().Y + bonusYLocation, spawnedChunks[xMap.first][yMap.first]->GetActorLocation().Z)))); \
if (chunkReference != nullptr) \
{ \
chunkReference->bonusX = bonusX; \
chunkReference->bonusY = bonusY; \
UGameplayStatics::FinishSpawningActor(chunkReference, FTransform(FRotator(0, 0, 0), FVector(spawnedChunks[xMap.first][yMap.first]->GetActorLocation().X + bonusXLocation, spawnedChunks[xMap.first][yMap.first]->GetActorLocation().Y + bonusYLocation, spawnedChunks[xMap.first][yMap.first]->GetActorLocation().Z))); \
}
I używam go w ten sposób:
else
{
SPAWN_CHUNK_WITH_PARAMS(spawnedChunks[xMap.first + 1][yMap.first + 1], 5000, 5000, 9, 9)
}
Tylko problem w tym, że wywala mi błędy: syntax error: 'constant', xMap is not a member of AWorldGenerator, spawnedChunks is not a member of AWorldGenerator, first is not a member of AWorldGenerator. Jest o tyle ciekawiej, że gdy z makra usunę tą część:
chunkReference->bonusX = bonusX; \
chunkReference->bonusY = bonusY; \
To wszystko dobrze działa. Używam makra zamiast funkcji, bo ten sam kod w funkcji skutkował crashem gry, a bez funkcji już nie. Spawned chunks to mapa obiektów AWorldGenerator, a xMap i yMap to iteratory