Be the first to post for 'Generating Random Numbers'!

If you’re reading this, there probably aren’t very many posts yet. But don’t worry, you can be the first! Either create a new post or just reply to this one to say ‘hi’.

1 Like


Lots of magic numbers in this lecture. While the size is certainly static for now, if a designer wanted to change the size of the Tile in some way, this code would break, making it pretty brittle. Could we have a lecture added to read the bounds of the tile dynamically?


Thanks so much for pointing this out.

@sampattuzzi can you check for magic numbers, parameterise, annotate video and fix in future video please. The problem is here…

void ATile::PlaceActors() {
 	FVector Min(0, -2000, 0);
 	FVector Max(4000, 2000, 0);
 	FBox Bounds(Min, Max);
 	for (size_t i = 0; i < 20; i++)
 		FVector SpawnPoint = FMath::RandPointInBox(Bounds);
 		UE_LOG(LogTemp, Warning, TEXT("SpawnPoint: %s"), *SpawnPoint.ToCompactString())

It’s already done in about 2-3 lectures time

void ATile::PlaceActors(TSubclassOf<AActor> ToSpawn, int MinSpawn, int MaxSpawn, float Radius, float MinScale, float MaxScale)
	int NumberToSpawn = FMath::RandRange(MinSpawn, MaxSpawn);
	for (size_t i = 0; i < NumberToSpawn; i++)
		FVector SpawnPoint;
		float RandomScale = FMath::RandRange(MinScale, MaxScale);
		bool found = FindEmptyLocation(SpawnPoint, Radius * RandomScale);
		if (found) {
			float RandomRotation = FMath::RandRange(-180.f, 180.f);
			PlaceActor(ToSpawn, SpawnPoint, RandomRotation, RandomScale);

Not quite. I have indeed hardcoded the bounds of the tile. That should be exposed, my bad. Will fix it in the next lecture we touch the tile class.

Privacy & Terms