Binary ‘==’: no operator found? FTransform == FTransform

I’m not sure why is this thread still opened after 75 posts and why are you trying to rewrite a function already present in the engine (that I linked in the 10th post), I tried to read everything and I hope I didn’t miss anything important.

Said that, you are really reinventing the wheel:

.h File
	TArray<FTransform> ArrayOfTransforms;
	TArray<FTransform> UsedLocations;
	FTransform SpawnLocation;

	bool FindRandomSpawnLocation();
.cpp File
bool ATransformTest::FindRandomSpawnLocation()
{
	FTransform RandomLocation = ArrayOfTransforms[FMath::RandRange(0, ArrayOfTransforms.Num() - 1)];

	for (auto CurrentTransform : UsedLocations)
	{
		if(UKismetMathLibrary::EqualEqual_TransformTransform(RandomLocation, CurrentTransform))
		{
			UE_LOG(LogTemp, Warning, TEXT("Location already used"));
			return false;
		}
	}

	SpawnLocation = RandomLocation;
	UsedLocations.Add(RandomLocation);
	return true;
}

The function FindRandomSpawnLocation() gets a random value in the transform array (you should replace it with your GetAllTransform function).
It returns false if the location is already present in UsedLocations, otherwise it sets the SpawnLocations and adds it to the UsedLocations.

You can re-call the function if it returns false, but be careful because if all locations are used you could enter an infinite loop.

A more efficent way would be probably to use an array called “AvailableLocations” and get a random value from it, then remove it, so you don’t have to check every time if it’s used.

1 Like