Bug reported as well, but I need this to work right now for a project I am in the middle of - and bug reports generally take weeks to get a response…
Hopefully someone knows of a workaround!
I am running the latest Unity Editor release (2.5.1f5) on a MackBook Pro with Mac OS 10.5.7.
I have this script in my project’s “Editor” folder":
class TestWindow extends EditorWindow {
var str : String;
@MenuItem ("Window/Test Window")
static function Init () {
var window : TestWindow = EditorWindow.GetWindow(TestWindow);
}
function OnGUI () {
GUILayout.Space(6);
str = EditorGUILayout.TextField(GUIContent("Click to Crash","GUITOOLTIP"), str);
}
}
I open Window > Test Window, focus the textfield in my test window by clicking it, and the textfield dissapears while Unity says:
NullReferenceException: Object reference not set to an instance of an object
UnityEngine.TextEditor.ClampPos ()
UnityEngine.TextEditor.MoveCursorToPosition (Vector2 cursorPosition)
UnityEditor.EditorGUI.DoTextField (UnityEditor.RecycledTextEditor editor, Int32 id, Rect position, System.String text, UnityEngine.GUIStyle style, System.String allowedletters, System.Boolean changed, Boolean reset, Boolean multiline, Boolean passwordField) (at /Users/build/builds/unity-branches-2.5.x/unity-2.5.x/Editor/Mono/Generated/EditorGUI.cs:306)
UnityEditor.EditorGUI.TextField (Rect position, UnityEngine.GUIContent label, System.String text, UnityEngine.GUIStyle style) (at /Users/build/builds/unity-branches-2.5.x/unity-2.5.x/Editor/Mono/Generated/EditorGUI.cs:640)
UnityEditor.EditorGUI.TextField (Rect position, UnityEngine.GUIContent label, System.String text) (at /Users/build/builds/unity-branches-2.5.x/unity-2.5.x/Editor/Mono/Generated/EditorGUI.cs:635)
UnityEditor.EditorGUILayout.TextField (UnityEngine.GUIContent label, System.String text, UnityEngine.GUILayoutOption[] options) [0x00028] (at /Users/build/builds/unity-branches-2.5.x/unity-2.5.x/Editor/Mono/Generated/EditorGUI.cs:2318)
TestWindow.OnGUI () (at Assets/_World Tools/Editor/TestWindow.js:10)
System.Reflection.MonoMethod.Invoke (System.Object obj, BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture) [0x00000]
I remove the label from the textfield, and everything works fine. Specifying the label as a String instead of a GUIContent does not help.
I can’t believe such an obvious bug made it into a production version of Unity! Hopefully someone can see something that I am doing wrong, or can think of a workaround…