How to overload operator == for (TArray)?

It’s not a function created by you that you are returning, so that is like one problem with the types, second problem is it you are overloading it ? as I can see that parameter is only one inside the function and you got two params on the function call.

It only has one parameter in the form of a pointer with it’s type named item

SizeType Find(const ElementType& Item) const
	

So maybe when you call array find you are calling more than one function and this is just one of them ? otherwise you can’t fit two parameters on a call to a function that only has to offer one.

Is this created by you ?

SizeType Find(const ElementType& Item) const
	{
		const ElementType* RESTRICT Start = GetData();
		for (const ElementType* RESTRICT Data = Start, *RESTRICT DataEnd = Data + ArrayNum; Data != DataEnd; ++Data)
		{
			if (*Data == Item)
			{
				return static_cast<SizeType>(Data - Start);
			}
		}
		return INDEX_NONE;
	}```
1 Like

No, this is the part of the Array_Find function

template<typename T, typename U>
    static int32 Array_Find(const TArray<T>& TargetArray, const U& ItemToFind)
    {
        return TargetArray.Find(ItemToFind);
    }

It has two parameters so array find calls on multiple locations one the find function then a Template array, okay, template meaning for template, it can be any kind ?

So that is the first parameter and it’s calling not on the find function as I see, Location is calling on it. You gave wrong function.

First parameter is 
TransformArray
Second is  Location

The Array_find calls on multiple locations not just in one place

You made a Ftransfrom parameter for:

TArray<T>& TargetArray

and another parameter named Location for the function you posted.

const U& ItemToFind

So you induced us in error :slight_smile:

Actuall the last parameter is for the function

const U& ItemToFind
const TArray<T>& TargetArray,

This has nothing to do with the function posted by you, it may be valid for your Ftransform because it’s a Template array I take it the stands for any type of template and since FTransfrom is a template part of the Tarray is aceptable.

So most probally it’s the INT.

You are tryig to say that the template array parameter that now is of Ftransform is to be stored inside an INT variable called index.

So things have cleared up regarding your Ftransfrom, it was a parameter for < T > type “teplate type” and it is the first parameter as I see the function is detailed in the unreal docs now. The second parameter “Location” is for that function, only the second one.

1 Like

I understand and thank You for the detailed information , really learned new things from your answer :slightly_smiling_face:

Problem is with INT.
Just for the fun of it, make an Ftransform instead of INT.

Sort of

FTransfrom  somevar;

somevar = FCustomThunkTemplates::Array_Find(TransformArray, Location);

If no error is shown then it is in fact the INT, I don’t see any form of conversion in your code.

Why are you bent on using Ftransfrom, use vectors dear.

1 Like

than You for correcting me, it works perfectly but I got some empty locations, do you hve any idea what is this?

It can also be that the universal < T > array teplate is not accepting your Ftransform for some reason and it says that it’s a conversion error. Maybe you should check how to set types on the array, or what types does < T > accept

1 Like

I am bent using transform becasue vector will not help me in case I am spawning the actors in the world space transforms of the level using GetComponentTransforms

Sir I think GetComponentTransform is only available for FTransform

I’m not sure how this works < T > , I’m not familiar with it, I never used it.
But that might be the problem also, as it is not recondising your Ftransform and thinks you want to convert from it to < T > and it may not find the type of Ftransform compatible with it.

1 Like

I am bent using transform becasue vector will not help me in case I am spawning the actors in the world space transforms of the level using GetComponentTransforms

You can do that with vectors with functions.

1 Like

can you show a snapshot of the printed locations? I have no idea what locatoins are you talking about


i mean duplicates location

floats are bolted values and use nearlyequal instead of ==

hope it helps
cheers!

how to use nearlyequal under ContainsByPredicate ?

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

this doesn’t compiles :tired_face:

:rofl: nearlyequal
test it and show the results

return Transform.GetLocation().Equals(Location.GetLocation(), KINDA_SMALL_NUMBER);

hope it helps,
cheers!

1 Like

still got few locations duplicated

Solved your problem ?
Now that I’m rested :slight_smile: I can see that var location is also a Ftransfrom.
So as I said no Ftransform in that function, Location parameter is suppose to input a value for the function return that you have there that returns parameter “Item” I believe that is not of Ftransform Type.
ElementType is the type being return there with the name "Item:
Maybe element type accepts all things maybe not Ftransform, or maybe also Ftransform.

I got a page here

From the page

operator==

(
TArrayView< ElementType, SizeType >,
TArrayView< OtherElementType, Other…
)
So if you are trying to match things this should be a good resource.
Why is it giving “==” error , I don’t see this operator in your code now posted by you
I understand the conversion error tho on the Ftransform where you are trying to fit Ftranssform into universal types and maybe they don’t like Ftransform.

1 Like

yes this is confusing, we see the code without == but internally I am sure some comparison is happening because this is returning the index of the FTransform in the Ftransform Array

Index = FCustomThunkTemplates::Array_Find(TransformArray, Location);

example:

FindIndex = FCustomThunkTemplates::Array_Find(Available, Location);
bEqualValid = UKismetMathLibrary::EqualEqual_IntInt(FindIndex, -1);

i updated the question, thank you for correcting me )

Wait wait

 UKismetMathLibrary::EqualEqual_IntInt

UKismetMathLibrary converts things, I use this lib often.
I don’t see UKismetMathLibrary in your code.

It’s obvious, at the end it has " FindIndex So the error is there when it’s trying to compare FindIndex with this library.

So it’s obvious that your Ftransform is not being converted to “int” as stated by me it’s the INT not converted. So Find Index is not an int, tho you made it an INT.
The error happens at the library level where it’s trying to equal int to int, it finds that Ftransform is not an INT and gives you the error

no operator found which takes a left-hand operand of type ‘const FTransform’

1 Like