I haven’t looked to much into TArray, TSet and TMap yet, but here some general explanation:
Arrays keep their elements in order. And elements are accessed by their index.
So if you wanted to get a specific Item of your TArray you would have to go through all elements of your array and check if this element was your desired one.
Pseudocode:
for (index = 0; index < MyTArray.size(); index++){
Element e = MyTArray[index];
if (e == searchedElement){
return element;
}
}
Sets do not care about the order of their elements. To access an object of a Set, you actually need the object itself since from the object the index is generated to find the element directly.
So you do not need to iterate over the whole array anymore to find an object, you would simply ask “do I have this object”. The Set would generate the index of this object. And if it is there then you know it directly.
You only touched 1 element of your Set! And not all like for the Array.
Sets are really cool if you want to remember e.g. which objects are already done with calculating some stuff. You just want to know if it’s there. E.g. has playerA already joined a team?
The are no duplicates allowed due to the fact, that the index is generated by the object.
If you would try to add the same object twice, both these objects would get the same index and then you couldn’t decide anymore which object was actually the real one. Actually for Sets this shouldn’t hurt, since it would have to be the same object to create such a collision (to generate the same index twice).
A Maps is like a Dictionary.(they are called like this in C#)
Maps consists of Key, Value -Pairs.
You have to know the Key to access the corresponding Value. If you compare it with a regular dictionary. The key would be the word you are looking for. The explanation of the word is the value.
e.g. you have several configurations to generate a level on runtime. These configurations are stored in a Map with Key = String and Value = Configuration.
The cool part about this one is, that you don’t have to know any index of the Configuration, only how you would call it. So if you wanted the configuration of Level “Supercool” you would access it kind of like
Configuration config = MapOfConfigs"Supercool"];
Again like a set access time is kind of instant, since the index is generated through the key. However if you use the same key twice: To which value should the key point then? -> That’s the reason why no duplicates are allowed.
I would suggest to google these names: Array, Hashset, Hashmap