【发布时间】:2015-01-12 00:49:13
【问题描述】:
我了解以下错误消息是在(通常)Unity 告诉我 myProg 脚本第 54 行中的某件事不存在时引起的:
NullReferenceException: Object reference not set to an instance of an object
myProg.OnGUI () (at Assets/Scripts/Editors/myProg.cs:54)
但就我所见所想,那里没有任何遗漏......
这里是代码sn-p的相关部分,第54行是.enabled的位(中间行):
if( GUILayout.Button("SART07Johnson") )
{
stage.setFatigueInductor( new Sart07JohnsonDefinition(GetComponent<ExperimentCreator>().getExperiment().getAvailableTableName("SART07Johnson")) );
stage.setTypeOfFI( FatigueType.SART07Johnson );
SART07JohnsonEditor editorSart07Johnson = GetComponent<SART07JohnsonEditor>();
editorSart07Johnson.enabled = true;
editorSart07Johnson.Init( (Sart07JohnsonDefinition)stage.getFatigueInductor(), this.stage.StageName,GetComponent<ExperimentCreator>().getExperiment().GetExperimentName() );
GetComponent<NavigationTree>().CurrentEditor = editorSart07Johnson;
this.enabled = false;
}
所以,我想知道...还有什么问题?我可以调查的任何其他可能导致生成此错误消息的具体原因?
【问题讨论】:
-
一般来说,错误信息不会“撒谎”,我建议您发布所涉及的实际代码,以便人们可以验证它不是导致问题的代码。
-
你需要给我们看第 54 行,伙计。
-
谢谢大家。我添加了那条特定的行,但我没有这样做的原因是因为它需要我发布 GetComponent 引用的其他程序......
-
这个脚本附加的GameObject包含一个“SART07JohnsonEditor”组件?
-
是的,GetComponent
引用了一个名为 SART07JohnsonEditor 的现有 C# 脚本
标签: unity3d nullreferenceexception