Is it better to store index list or object itself ?
First of all, sorry for the mistakes, english is not my native tongue.
I will try to explain clearly my question :
I have a class, named "character", which contain informations about my characters, like first name, surname, etc...
All existing characters are stored into a list, named "charactersList", and each time i create a new character, i add it to this list. Like this :
public class Character : MonoBehaviour {
public static List<Character> characterslist;
public Character()
{
characterslist.Add(this);
}
I want to create a variable 'father' who contain a reference to another character. Knowing that I will never sort the 'characterList' list, is it better to store the index list in the variable 'father' or directly the character ?
Here is an example : I have my character Luke that i just created, and i want to store his father Anakin who's stored at index 42 in the 'characterList'.
Should i do :
Luke.father = 42;
Or
Luke.father = characterList[42];
Hope i'm clear and thanks for your help.
Your answer
![](https://koobas.hobune.stream/wayback/20220612120604im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Finding all the same strings in a List 2 Answers
index number problems Forloop 1 Answer
I need help finding the index of an object in a list. 1 Answer
Unknown Argument Out of Range Index Error On Card Game 1 Answer
[ANSWERED] IndexOf and LastIndexOf both returning -1 when an item is on the list. 1 Answer