Event.CommandName : in == NULL error

I’m trying to use Event.CommandName in an EditorWindow.

When I add this code to OnGUI() I get a continuous stream of "in == NULL’’ errors in the log.

The code is straight from the documentation:

Event e = Event.current;
if (e.commandName != "")
Debug.Log("Command: " + e.commandName);

What am I doing wrong? Or is it broken?

Using Unity 3 Pro.

[EDIT] Just to check, I made a new project with nothing else going on and it still happens.

Here’s the full error:

in == NULL
UnityEngine.Event:get_commandName()
CommandTest:OnGUI() (at Assets/Editor/CommandTest.cs:67)
UnityEditor.DockArea:OnGUI()

Solved. It appears the example in the docs is wrong. You just have to check that the current event is EventType.ExecuteCommand before you attempt to read commandName.

if (Event.current.type == EventType.ExecuteCommand  Event.current.commandName != "")
    Debug.Log("Command: " + Event.current.commandName);

In case anyone else runs into this problem.

The docs should probably be clearer on this point…