How can I simulate the "f" hotkey in the editor?

I want to write a script to add a menu item that, when clicked, brings the main character into focus in the Scene view. So far, I can't seem to get it or find any resources on how to change the scene view's camera position/rotation.

How can I set the position/rotation of the scene view's camera in the editor at design-time?

According to this tread:

You can use:


It works for me, although because it is undocumented, it is subject to not work or change.

I have mine set up as an editor script button:

if(GUILayout.Button("Frame Camera", GUILayout.Width(120)))

Hope this helps!

An alternative to @noahmjohnson 's answer:


For the other editor commands, refer to their name in the Edit menu of the Unity Editor window (triming spaces).

See EditorGUIUtility.CommandEvent and EditorWindow.SendEvent

Try Jaap's answer to my similar question earlier:

You can't at design-time, only run-time.