Blueprint to C++ and Engine Freezing?

I am not removing the unique location nor unique transform of the container, I remove the random item place in one of the container in item group which has 5 containers , and place corresponding ammo type the weapon in the group.

the item removed will have chance to hit again and spawn in another group

Please use a Set if you need uniqueness. It literally does it for you as itā€™s impossible to add a duplicate item to a set.

Hereā€™s some brief overview of a TSet in unreal. IE you can have TSet<FTransform> (This works for BP too!)

If you need them to be findable by index use a map! They are a unique pair! Also blueprints

TMap<int, FTransform>

Sets ā†’ TSet | Unreal Engine Documentation

Maps ā†’ TMap | Unreal Engine Documentation

1 Like

The problem is not the TArrays but the problem is the find function and == not working with FTransform Arrays, I canā€™t do something like :

if(TransformArray.find(TransformLocation) == -1) {}

if You think Sets or Maps will work , please write an solution so i can get rid of this issue. :tired_face:

My opinion is based only on the code you showed(in another thread)
I;m little confused, because what you wrote is contrary to what can be read in the code.

Tell me why it canā€™t be look like:

//...
ItemGroupRef->GetAllTransforms(Available);
Algo::RandomShuffle(Available);
for (auto SpawnArrayElements : ItemsIDArr) {
	SpawnType = SpawnArrayElements.Type;
	SpawnID = SpawnArrayElements.ID;
	auto SpawnLocation = Available.Last();
	Available.Pop();
	switch (SpawnType) {
		// ...
1 Like

You need to overload the == operator for transforms. Iā€™d declare this function in some kind of namespace so you donā€™t step on other declarations if you encounter any.

FORCEINLINE bool operator==(const FTransform& LTransform, const FTransform& RTransform)
{
	return
		(
			LTransform.ToMatrixNoScale() == RTransform.ToMatrixNoScale()
		);
}

That will compare the orientation and translation of two transforms to decide equivalence

FORCEINLINE bool operator==(const FTransform& LTransform, const FTransform& RTransform)
{
	return
		(
			LTransform.GetLocation() == RTransform.GetLocation()
		);
}

That one will decide equivalence only based off of locations. In which case, if you donā€™t care about rotations for what you are doing I would just switch now to using FVectors for locations because they already have an == operator :slight_smile: and they have a smaller footprint.

I would declare this in the header of the class that needs it to keep it within a namespace

1 Like

Sir this I have already, (Ftransfrom == Ftransform) the issue is need to do something to find the index of the array like
Index = FCustomThunkTemplates::Array_Find(TransformArray, Location);

Sir do I need to create a member for Algo RandomShuffle ? copiler says algo donā€™t have a member RadomShuffle

I think you are misunderstanding what Find does for TArrays in c++.

If you have TArray<FTransform> Transforms;

Transforms.Find(SomeTransform); ā† this will return the INDEX the transform is at in the array if it exists.

Therefore you now need to get the value at the index, like so.

FTransform TransformToFind = Transforms[Transforms.Find(TransformImTryingToFind)];

1 Like

image_2022-08-24_212559063

If I directly translate you blueprint code it would look like this.

UsedLocations.Add(Available[UsedLocations.Find(Location)]);

Or

UsedLocations.AddUnique(Available[UsedLocations.Find(Location)]); ā† Requires operator overloading (Which you said you have)

1 Like

and then how to get the return index to compare if == -1

There are better ways to write this code - but Iā€™ll keep it explicit so you can see whatā€™s going on - Directly from your blueprint code

const int LocationFoundAtIndex = UsedLocations.Find(Location); //<-Saves the index you found
if(LocationFoundAtIndex == -1)
{
//Do Something
}
else
{
 SpawnLocation = Location;
 UsedLocations.Add(SpawnLocation);
}
1 Like

says == no operator found, left hand operand...

I donā€™t get that error, it must be somewhere else in your code base.

1 Like

this is the full error
binary '==': no operator found which takes a left-hand operand of type 'const FTransform' (or there is no acceptable conversion)

You probably donā€™t have an == operator for the CONST version of FTransform. You can either remove the const on const FTransform where the error is or add another operator for == for the const version of FTransform.

1 Like

it sends me here in array.h

You are going way to deep.

The error is telling you that you donā€™t have the proper operator== for ā€œconst FTransformā€

Meaning you probably have

FORCEINLINE bool operator==(FTransform LTransform, FTransform RTransform)

but not also a

FORCEINLINE bool operator==(const FTransform LTransform, const FTransform RTransform)

1 Like

operator ==': error in function declaration; skipping function body

in my.h

FORCEINLINE bool operator==(const FTransform LTransform, const FTransform RTransform);

in my.cpp

FORCEINLINE bool AmyGameMode::operator==(const FTransform LTransform, const FTransform RTransform)

{
	return
		(
			LTransform.GetLocation() == RTransform.GetLocation()
			);
}

binary ā€˜operator ==ā€™ has too many parameters