Inside Map (find)?

Since a Map is an array, would “finding” be the same as looping and comparing each item?

A map is not an array. An array can hold copies, a map can’t.

I don’t know if the code loops or uses a hash key, but it does have to search in some sense.

Trying to find a solution that doesn’t involve looping through an Array.

I have a Grid of Squares variable in size and have made a Struct with an X/Y value including a reference to the Square (Static Mesh Component) added to an Array. I’m looping through comparing the X/Y e.g. 2/5 in the struct to get the component, atm though considering using a Map instead but don’t know if it would make any difference.

Yes, with a map, you could instantly lookup the component using a vector 2D ( or your struct ).

But, if you already have the X/Y, do you have the component reference, or is that what you’re looking up?

What I mean is, what are you trying to do with these squares, what caused you to decide to have a lookup of some sort?

To get a component reference, the Squares are Components in one Actor. In order to change it’s Material.

Half the time the answer lies in the way you interact with those components. There may be no need to ID / Map anything. Other times it’s a must. How are you choosing the component to change the material of?

Looking up in a map is faster than in an array. It’s almost comparable to already knowing where something is.

And IntPoint | Component map could work well for 2d coords. (Int Vector for 3D)


That’s what I’m using atm thanks.