Randomize Array of FTransform and compare if the elements are duplicated C++?

Well like I said earlier, after you call RandomLocation, you need to have a do while, otherwise it will just stop if the random transform returned is not one that hasn’t been used before. So you need to do something like:

do
{
	RandomLocation(Available, Location);
}
while (UsedLocations.ContainsByPredicate([Location](const FTransform Transform)
	{
		return Transform.GetLocation() == Location.GetLocation()
			&& Transform.GetRotation() == Location.GetRotation()
			&& Transform.GetScale3D() == Location.GetScale3D();
	}));

SpawnLocation = Location;
UsedLocations.Add(SpawnLocation);

But I don’t recommend this, this can potentially cause freezes

This will keep getting a random element until it finds one that is not in the UsedLocations array

1 Like