if it runs with in the sequence of 2 steps it freezing the engine only if the logic implemented in pure C++. First i wlll show the blueprint with sequence and then C++ code which is freezin the engine.
the reason for the freez is is because the loop is always infinite since you are not giving a random range before comparing not returning any results to make the condition change in the loop.
in your .h file
bool TransformsEqual(TArray<FTransform> TransformArray, FTransform B)
{
for (FTransform A : TransformArray)
{
if (A.GetScale3D() == B.GetScale3D() && A.GetLocation() == B.GetLocation() && A.GetRotation() == B.GetRotation())
//in your blueprint you are using only location your previous post defines, so you can check here only for location and scale in case.
{
return false;
}
}
return true;
}
in your .cpp replace do/while loop at //Sequence 1
do
{
RandomLocation(Available, Location);
UsedLocations.Add(Location);
} while (TransformsEqual(Available, Location));
SpawnLocation = Location;
Thank You very much Sir for the solution but it works only 98%, the duplicate locations are spawned , some spawn items got the same location and they are overlapping each other
This will give you a unique set of transforms for a given range. I have not provided the “GetRandomTransform” function as you might already have one.
The key question is why you cannot guarantee the uniqueness of the locations at the generation stage? (you take it from meshes, but at some point before you need to set it to that meshes)
Guaranteeing uniqueness during creation would simplify the entire process as much as possible, because it would be enough to
1.) grab locations
2.) shuffle
3.) just assign one by one to items
locations are itself unique, the containers transforms are itself unique.
I already takes a unique Location from the array of random range Location = Available[FMath::RandRange(1, Available.Num() - 1)]; UsedLocations.Add(Location) // used for future checks if to know the location is used and can’t be duplicated SpawnLocation = Location
the next time it loops it make new random range by -1 if duplicated range, repeat randomizing.
as you can see everytime the mesh should take a new unique location to be spawned.
in blueprint the logic works becuase comparing memory behind the scene to unique address , but in C++ the loop goes just infinite and the engine freeze.
in unreal C++ FTransform don’t have a find function like in blueprint , I can’t make UsedLocations.find(Location) == -1 this is the main problem of the issue, I don’t know why the dev’s missed it… I don’t know how to overload my own method operator somehow