Quantcast
Channel: Latest Questions by khoatic
Viewing all articles
Browse latest Browse all 97

List in prefab instantiated object not saving after Awake

$
0
0
So im instantiating a prefab with a script attached to it. inside the prefab script it holds a List variable. right now Im testing to figure out what the problem is, but what seems to be happening is the data is being stored during the Awake function, but when the update begins all of that goes out the door. Is there any way to make it so this doesnt happen??? //Update Class public List NodeList ; public void Awake() { NodeList = new List(); PrefabInst tmp = (Instantiate(Node, new Vector3(0, 20, 0), Quaternion.identity) as GameObject).GetComponent(); PrefabInst tmp2 = (Instantiate(Node, new Vector3(20, 20, 20), Quaternion.identity) as GameObject).GetComponent(); tmp.addLinkedNode(tmp2); tmp2.addLinkedNode(tmp); NodeList.Add(tmp); NodeList.Add(tmp2); Debug.Log(NodeList[0].linkedNodes[0]);//Not null - good Debug.Log(NodeList[1].linkedNodes[0]);//not null - good NodeList[0].setMoverStart();//give size of 1 - good NodeList[1].setMoverStart();//give size of 1 - good } public void Update() { Debug.Log(NodeList[0].linkedNodes[0]);//is null - ??bad?? Debug.Log(NodeList[1].linkedNodes[0]);//is null - ??bad?? NodeList[0].setMoverStart();//give size of 0 - ??bad?? NodeList[1].setMoverStart();//give size of 0 - ??bad?? } //PrefabInst class public List NodeList ; public void setMoverStart() { Debug.Log(this.linkedNodes.Count); }

Viewing all articles
Browse latest Browse all 97

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>