string hoge;
で宣言して、
this.hoge = GUILayout.TextField(this.hoge, 200);
とすると、
NullReferenceException: Object reference not set to an instance of an object UnityEngine.GUI.DoTextField (Rect position, Int32 id, UnityEngine.GUIContent content, Boolean multiline, Int32 maxLength, UnityEngine.GUIStyle style, System.String secureText, Char maskChar) UnityEngine.GUI.DoTextField (Rect position, Int32 id, UnityEngine.GUIContent content, Boolean multiline, Int32 maxLength, UnityEngine.GUIStyle style, System.String secureText) UnityEngine.GUI.DoTextField (Rect position, Int32 id, UnityEngine.GUIContent content, Boolean multiline, Int32 maxLength, UnityEngine.GUIStyle style) UnityEngine.GUILayout.DoTextField (System.String text, Int32 maxLength, Boolean multiline, UnityEngine.GUIStyle style, UnityEngine.GUILayoutOption[] options) UnityEngine.GUILayout.TextField (System.String text, Int32 maxLength, UnityEngine.GUILayoutOption[] options) BattleStateMachineMultiEditor.ShowCustomGUI () (at Assets/Scripts/Multi/MultiBattle/Editor/BattleStateMachineMultiEditor.cs:127) BattleStateMachineMultiEditor.OnInspectorGUI () (at Assets/Scripts/Multi/MultiBattle/Editor/BattleStateMachineMultiEditor.cs:86) UnityEditor.InspectorWindow.DrawEditor (UnityEditor.Editor editor, Int32 editorIndex, Boolean forceDirty, System.Boolean& showImportedObjectBarNext, UnityEngine.Rect& importedObjectBarRect, Boolean eyeDropperDirty) (at /Users/builduser/buildslave/unity/build/Editor/Mono/Inspector/InspectorWindow.cs:1211) UnityEditor.DockArea:OnGUI()
のエラー(一応実行はできるエラー)
http://answers.unity3d.com/questions/374959/c-textfield-null-reference-exception.html
string hoge;
のように初期化必須だった。 デフォルトで初期化されないのか??
おそらく、stringはNullable 型なので初期値はnull。"“ではない模様・・。 ちなみに
Nullable 型にできるのは null 非許容型(Nullable 型を除く値型)のみです。 したがって、string? というのは定義できません(参照型に ? を付けるのは無効)。 また、Nullable 型をさらに Nullable にすることはできず、 int?? (Nullable 型の Nullable 型)と言うのもエラーになります。