- Home /
Question by
Quest_for_stuff · Nov 21, 2020 at 09:03 PM ·
instantiateprefabprefabslistsprefab-instance
Do I necessarily need to instantiate a prefab before putting it in List to conserve his variable data?
For example : (panelList in a List of Type Panel)
This will make my List a size 2 list containing one prefabs with the letter type "A" and the second one with letter type "B".
panel.type = "A";
GameObject temp = Instantiate(panel.gameObject);
GameAsset.i.panelList.Add(temp.GetComponent<Panel>());
panel.type = "B";
GameObject temp = Instantiate(panel.gameObject);
GameAsset.i.panelList.Add(temp.GetComponent<Panel>());
This will make all my List a size 2 list containing two identic prefabs with the letter type "B".
panel.type = "A";
GameAsset.i.panelList.Add(panel);
GameObject temp = Instantiate(panel.gameObject);
panel.type = "B";
GameAsset.i.panelList.Add(panel);
GameObject temp = Instantiate(panel.gameObject);
Debug.log (panelList[0].type) will give "A" for the first example but "B" from the second example.
I though I only had to put prefabs in a list before Instantiating them to save the list after. Is there another option? Thank you!
Comment