NullReferenceException UnityEngine.Transform.get_localPosition

NullReferenceException  UnityEngine.Transform.get_localPosition

unity程序中,需要取得GO自身的Transform,出现如上空异常,这看起来很荒谬。

其实是代码其他函数中,获取对象发生异常,比如在编辑器中没有赋值就使用。出现引用异常。

这就会间接导致程序出现如上异常。

unity3d经常因为程序某个函数出现问题,而导致全局脚本出现引用失效。

unity3d官方论坛解释。

NullReferenceException are thrown when you try to access a reference variable that isnt referencing any object, hence it is null. So the first question, are all variables reference types?

http://answers.unity3d.com/questions/47830/what-is-a-null-reference-exception-in-unity.html

原文地址:https://www.cnblogs.com/2Yous/p/5079968.html