# How to overload operator == for (TArray)?

**URL:** <https://forums.unrealengine.com/t/how-to-overload-operator-for-tarray/633044>\
**Category:** C++\
**Tags:** UE4-20, unreal-engine, UE5-0, UE4, question, CPP\
**Created:** [August 24, 2022, 2:47am UTC](https://forums.unrealengine.com/t/how-to-overload-operator-for-tarray/633044 "2022-08-24T02:47:23Z")\
**Posts on this page:** 20\
**Page:** 3

<div class="post-metadata">

**Author:** ![Alexa.Ki](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/alexa.ki/32/562753_2.png) [@Alexa.Ki](https://forums.unrealengine.com/u/Alexa.Ki)\
**Post date:** [August 25, 2022, 7:14am UTC](https://forums.unrealengine.com/t/how-to-overload-operator-for-tarray/633044/41 "2022-08-25T07:14:05Z")

</div>

yes, it only not fails when comparing on blueprint side, the library is not 100% functional on C++ side, it need us to overload operator manually

---

<div class="post-metadata">

**Author:** ![Alexa.Ki](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/alexa.ki/32/562753_2.png) [@Alexa.Ki](https://forums.unrealengine.com/u/Alexa.Ki)\
**Post date:** [August 25, 2022, 7:15am UTC](https://forums.unrealengine.com/t/how-to-overload-operator-for-tarray/633044/42 "2022-08-25T07:15:47Z")

</div>

I am sure this is not a bug, this is just something I think only I am doing 😃

---

<div class="post-metadata">

**Author:** ![GigiK-K-K](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@GigiK-K-K](https://forums.unrealengine.com/u/GigiK-K-K)\
**Post date:** [August 25, 2022, 7:20am UTC](https://forums.unrealengine.com/t/how-to-overload-operator-for-tarray/633044/43 "2022-08-25T07:20:42Z")

</div>

> [@Alexa.Ki](#):
>
> Index = FCustomThunkTemplates::Array\_Find(TransformArray, Location);

From my point of view this is not possible.  
`Index = FCustomThunkTemplates::Array_Find(TransformArray, Location);`  
Location and Transform Arrays are Ftransform and index is an INT.  
There is not much information on “FCustomThunkTemplates” but if it does not offer a a conversion option you cannot convert these to your INT Index .

Smart thing to do is try at least a different aproach, turn your int variable into an int array and maybe since they are all arrays it will convert from array to array.

FCustomThunkTemplates, so I don’t think this is a conversion function, the math library converts things.

---

<div class="post-metadata">

**Author:** ![Alexa.Ki](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/alexa.ki/32/562753_2.png) [@Alexa.Ki](https://forums.unrealengine.com/u/Alexa.Ki)\
**Post date:** [August 25, 2022, 7:21am UTC](https://forums.unrealengine.com/t/how-to-overload-operator-for-tarray/633044/44 "2022-08-25T07:21:01Z")

</div>

> [@GigiK-K-K](#):
>
> Solved your problem ?

still not 100%.  
the expected result is like this, I got this result when done in blueprint.

 ![image_2022-08-25_040807277](https://d3kjluh73b9h9o.cloudfront.net/original/4X/d/5/7/d57931261a95e2720ab5fe2579eda2f73ddad205.jpeg)  
from this data table  
 ![lbp1](https://d3kjluh73b9h9o.cloudfront.net/original/4X/f/9/8/f988c055fcce468d14450090d5632e0cde10dc6f.png)

---

<div class="post-metadata">

**Author:** ![Alexa.Ki](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/alexa.ki/32/562753_2.png) [@Alexa.Ki](https://forums.unrealengine.com/u/Alexa.Ki)\
**Post date:** [August 25, 2022, 7:23am UTC](https://forums.unrealengine.com/t/how-to-overload-operator-for-tarray/633044/45 "2022-08-25T07:23:15Z")

</div>

> [@GigiK-K-K](#):
>
> From my point of view this is not possible.

don’t know but in blueprint it working, don’t know what type of conversion is happening behind the scene.

```auto
do
	{
		switch( __CurrentState )
		{
		case 1:
			{
				if(::IsValid(ItemGroupRef))
				{
					(AllTransforms).Reset();
					ItemGroupRef->AItemGroup::GetAllTransforms(/*out*/ AllTransforms);
				}
				AMyGameMode::RandomLocation(AllTransforms, /*out*/ Location);
			}
		case 2:
			{
				FindIndex = FCustomThunkTemplates::Array_Find(Available, Location);
				bEqualValid = UKismetMathLibrary::EqualEqual_IntInt(FindIndex, -1);
				if (!bEqualValid)
				{
					__CurrentState = -1;
					break;
				}
			}
		case 3:
			{
				SpawnLocaton = Location;
			}
		case 4:
			{
				AddArray = FCustomThunkTemplates::Array_Add(Available, SpawnLocaton);
				__CurrentState = -1;
				break;
			}
		default:
			break;
		}
	} while( __CurrentState != -1 );
}

```

---

<div class="post-metadata">

**Author:** ![GigiK-K-K](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@GigiK-K-K](https://forums.unrealengine.com/u/GigiK-K-K)\
**Post date:** [August 25, 2022, 7:28am UTC](https://forums.unrealengine.com/t/how-to-overload-operator-for-tarray/633044/46 "2022-08-25T07:28:57Z")

</div>

> [@Alexa.Ki](#):
>
> `bEqualValid = UKismetMathLibrary::EqualEqual_IntInt(FindIndex, -1);`

I did not see this in your code in the previous posts

```auto
bEqualValid = UKismetMathLibrary::EqualEqual_IntInt(FindIndex, -1);

```

it’s a bool and if it meets the requirements meaning it finds a match it will turn to true.

Is this made by you ?

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

```

Or did you find it in a tutorial ?  
From what I can see when you call on the math lib FindIndex is suppose to be an int already, meaning the values have been converted with FCustomThunkTemplates, from the floats of the Ftransfrom to Int values, I don’t see any other functions there responsible for conversions.

---

<div class="post-metadata">

**Author:** ![Alexa.Ki](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/alexa.ki/32/562753_2.png) [@Alexa.Ki](https://forums.unrealengine.com/u/Alexa.Ki)\
**Post date:** [August 25, 2022, 7:29am UTC](https://forums.unrealengine.com/t/how-to-overload-operator-for-tarray/633044/47 "2022-08-25T07:29:21Z")

</div>

when we see the result output, it seems to me that the location vector transform is randomized by -1 subtraction.  
location `x.5738` was changed to `x5638`

---

<div class="post-metadata">

**Author:** ![Alexa.Ki](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/alexa.ki/32/562753_2.png) [@Alexa.Ki](https://forums.unrealengine.com/u/Alexa.Ki)\
**Post date:** [August 25, 2022, 7:31am UTC](https://forums.unrealengine.com/t/how-to-overload-operator-for-tarray/633044/48 "2022-08-25T07:31:01Z")

</div>

> [@GigiK-K-K](#):
>
> I did not see this in your code in the previous posts

after lots of tries, I decided to generate the native code to see what is happening behind the scene, and found these datas and shared

---

<div class="post-metadata">

**Author:** ![GigiK-K-K](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@GigiK-K-K](https://forums.unrealengine.com/u/GigiK-K-K)\
**Post date:** [August 25, 2022, 7:31am UTC](https://forums.unrealengine.com/t/how-to-overload-operator-for-tarray/633044/49 "2022-08-25T07:31:10Z")

</div>

Hahha that is from relative possitioning because you did not transform vectors back and forth. It’s from Relative possitioning because they are not transformed properly and as I told you they can shift on world possition.

So relative possitions will cause shifts between items when transformed in an imporoper way to world. Meaning you did not transform to world possition in a porpoer maner and when you did the items that had relative position shifted.

---

<div class="post-metadata">

**Author:** ![Alexa.Ki](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/alexa.ki/32/562753_2.png) [@Alexa.Ki](https://forums.unrealengine.com/u/Alexa.Ki)\
**Post date:** [August 25, 2022, 7:34am UTC](https://forums.unrealengine.com/t/how-to-overload-operator-for-tarray/633044/50 "2022-08-25T07:34:14Z")

</div>

so I need to store the spawn points/locations in world transforms?

---

<div class="post-metadata">

**Author:** ![GigiK-K-K](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@GigiK-K-K](https://forums.unrealengine.com/u/GigiK-K-K)\
**Post date:** [August 25, 2022, 7:34am UTC](https://forums.unrealengine.com/t/how-to-overload-operator-for-tarray/633044/51 "2022-08-25T07:34:50Z")

</div>

You can’t leave relative position without transforming to world, they will constantly shift from different angles, perspectives , points of view of comparing things, if this == from this angle then it’s like this, it’s all relative and shifting. So world transfrorm is like a lock on relative once it’s applied corectly, the individual values will show up correct.

---

<div class="post-metadata">

**Author:** ![Alexa.Ki](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/alexa.ki/32/562753_2.png) [@Alexa.Ki](https://forums.unrealengine.com/u/Alexa.Ki)\
**Post date:** [August 25, 2022, 7:41am UTC](https://forums.unrealengine.com/t/how-to-overload-operator-for-tarray/633044/52 "2022-08-25T07:41:02Z")

</div>

I copied locations from this ralative location into data table, the spawn points.  
I need to make them world and then record?  
 ![image_2022-08-25_124000367](https://d3kjluh73b9h9o.cloudfront.net/original/4X/6/5/b/65bf0ad203f91eb8d785cfcb3f1f44e963420070.png)

---

<div class="post-metadata">

**Author:** ![GigiK-K-K](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@GigiK-K-K](https://forums.unrealengine.com/u/GigiK-K-K)\
**Post date:** [August 25, 2022, 7:44am UTC](https://forums.unrealengine.com/t/how-to-overload-operator-for-tarray/633044/53 "2022-08-25T07:44:24Z")

</div>

That is the problem, you need to convert them to world possition, and then compare with that. Relative position , I would also convert to local space even if it is local space then to world.

Relative position represents the distance of objects to the middle point representing the main actor of your class, or component, the main object, all these items are around it relative to it. So there is the middle point and then you have all these items with relative positions , relative meaning the distance coordinate offset from the middle of your main actor componet.

You are getting relative possitions from some where else ? and then adding them to your main component ? The main component has a middle point, root point and these have offsets from the main point. That is called Relative (to middle) how far from it.

---

<div class="post-metadata">

**Author:** ![Alexa.Ki](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/alexa.ki/32/562753_2.png) [@Alexa.Ki](https://forums.unrealengine.com/u/Alexa.Ki)\
**Post date:** [August 25, 2022, 7:46am UTC](https://forums.unrealengine.com/t/how-to-overload-operator-for-tarray/633044/54 "2022-08-25T07:46:30Z")

</div>

```auto
void AItemGroup::GetAllTransforms(/*Out*/ TArray<FTransform>& Transform)
{
for (auto Mesh : { StaticMesh01, StaticMesh02, StaticMesh03, StaticMesh04, StaticMesh05 })
		{
			if (IsValid(Mesh))
			{
				Transform.Add(Mesh->GetComponentTransform());
			}
		}
}

```

---

<div class="post-metadata">

**Author:** ![GigiK-K-K](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@GigiK-K-K](https://forums.unrealengine.com/u/GigiK-K-K)\
**Post date:** [August 25, 2022, 7:48am UTC](https://forums.unrealengine.com/t/how-to-overload-operator-for-tarray/633044/55 "2022-08-25T07:48:27Z")

</div>

not like that, you need to get location first on them.  
Location on staticmesh01 02 and so on, you are getting the location on world like this, you need the reative location of items.

Get relative location on them and with that transform. Without getting location you are getting world coordinates on the meshes that are offset really from the main component, and you are getting the main component coordinate because world does not know yet about your extra items.

Makes it easy with Vecotrs, I don’t use Ftransform.

---

<div class="post-metadata">

**Author:** ![Alexa.Ki](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/alexa.ki/32/562753_2.png) [@Alexa.Ki](https://forums.unrealengine.com/u/Alexa.Ki)\
**Post date:** [August 25, 2022, 7:49am UTC](https://forums.unrealengine.com/t/how-to-overload-operator-for-tarray/633044/56 "2022-08-25T07:49:16Z")

</div>

I have locations on them

 ![image_2022-08-25_125019432](https://d3kjluh73b9h9o.cloudfront.net/original/4X/b/2/f/b2f4630a13b9cd9a29b4018cd421390c42b3bb37.png)

---

<div class="post-metadata">

**Author:** ![GigiK-K-K](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@GigiK-K-K](https://forums.unrealengine.com/u/GigiK-K-K)\
**Post date:** [August 25, 2022, 7:52am UTC](https://forums.unrealengine.com/t/how-to-overload-operator-for-tarray/633044/57 "2022-08-25T07:52:36Z")

</div>

when we see the result output, it seems to me that the location vector transform is randomized by -1 subtraction.  
location `x.5738` was changed to `x5638`

It seems to me that the difffrence is neglectable and this is your problem, the items have shifted to middle point because you got the main component location middle and it’s giving you a shifted possition on them as an offset because the world position does not know about your relative objects.

---

<div class="post-metadata">

**Author:** ![Alexa.Ki](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/alexa.ki/32/562753_2.png) [@Alexa.Ki](https://forums.unrealengine.com/u/Alexa.Ki)\
**Post date:** [August 25, 2022, 7:54am UTC](https://forums.unrealengine.com/t/how-to-overload-operator-for-tarray/633044/58 "2022-08-25T07:54:53Z")

</div>

the world position does not know then why the items are spawned on the locations I want? and the problem is just they are duplicated, on one location 2 or 3 items are spawned

---

<div class="post-metadata">

**Author:** ![Alexa.Ki](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/alexa.ki/32/562753_2.png) [@Alexa.Ki](https://forums.unrealengine.com/u/Alexa.Ki)\
**Post date:** [August 25, 2022, 7:58am UTC](https://forums.unrealengine.com/t/how-to-overload-operator-for-tarray/633044/59 "2022-08-25T07:58:30Z")

</div>

![image_2022-08-25_125821752](https://d3kjluh73b9h9o.cloudfront.net/original/4X/7/9/3/7933a3ee53f77f39b424e83dbdbce2571520ec02.png)

---

<div class="post-metadata">

**Author:** ![GigiK-K-K](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@GigiK-K-K](https://forums.unrealengine.com/u/GigiK-K-K)\
**Post date:** [August 25, 2022, 7:58am UTC](https://forums.unrealengine.com/t/how-to-overload-operator-for-tarray/633044/60 "2022-08-25T07:58:33Z")

</div>

You need to shift your relative objects to world possition, so world possition knows about them, otherwise how can it ? if you don’t transform relative positions you have to world. If you don’t all the world knows about is the main component possition and the items you have it will see the same location for them as for the main root object.

So it’s going to take your relative positions you have and shift them to the middle and values are going to get scrabled. World does not know of your relative positions for the objects that have them, it must know and it’s why you have to transform them to world, once you do the world location will know about these items or better put their location, and it’s going to treat their position apart from the main component as a offset where they are and not shift everything where the middle point is.

But you got to know how to transform relative position to world.

[Previous page](https://forums.unrealengine.com/t/how-to-overload-operator-for-tarray/633044.md?page=2)

[Next page](https://forums.unrealengine.com/t/how-to-overload-operator-for-tarray/633044.md?page=4)
