Quantcast
Channel: Questions in topic: "error message"
Viewing all articles
Browse latest Browse all 2891

OnEnable called by disabled object

$
0
0
I just run into the problem, that it seeems the function OnEnable() is called by not enabled objects what causing my script to crash. Here is the code that produces the following error: *NullReferenceException: Object reference not set to an instance of an object* Code: void OnEnable() { CalculatePositions(); print("CalculatePositions() by OnEnable: " + transform.parent.parent.name); //ERROR HERE } It seems, the error is produced by accessing the name of the parent.parent of the code holding object. The parent.parent exists as you can see in following picture: ![alt text][1] But is not active (like the object that produces the error message). Could it be, that the OnEnable() function is called when instantiate an inactive object, causing this problem? If so, how can I work around that? [1]: /storage/temp/85766-onenableproblem.jpg

Viewing all articles
Browse latest Browse all 2891

Trending Articles



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