Change Near Clipping Plane Scene Camera

Hello there,

Is it possible to change the near clipping plane of the scene camera without focusing an object. I tried to change the near clipping plane via script, but when used as a handle it just clips gizmos (See gif). I also tried to set it via an own window, but in that case the change of the near clipping plane had no effect at all.

Here is the window script:

using UnityEngine;
using UnityEditor;

public class NearClippingEditorWindow : EditorWindow
{
  private static float nearClipping;

  [MenuItem("Window/Scene Camera clipping")]
  static void Init()
  {
  NearClippingEditorWindow window = (NearClippingEditorWindow)EditorWindow.GetWindow(typeof(NearClippingEditorWindow));
  window.Show();
  }

  void OnFocus()
  {
  var sceneCamera = SceneView.lastActiveSceneView.camera;
  if (sceneCamera == null)
  {
  Debug.Log("Scene Camera not found");
  return;
  }
  nearClipping = sceneCamera.nearClipPlane;
  }

  void OnGUI()
  {
  GUILayout.Label("Scene Camera", EditorStyles.boldLabel);
  var sceneCamera = SceneView.lastActiveSceneView.camera;
  if (sceneCamera == null)
  {
  Debug.Log("Scene Camera not found");
  return;
  }
  nearClipping = EditorGUILayout.Slider("Near clipping", nearClipping, 0.01f, 100f);
  sceneCamera.nearClipPlane = nearClipping;
  SceneView.lastActiveSceneView.Repaint();
  }
}

I think I am getting the correct camera, but my changes seem to have no effect. Any ideas what went wrong? I also attached the project to the post.

2957267–219414–EditorCamera.zip (39.1 KB)

1 Like

Did you find an answer to this? I hate the way the clipping plane goes all wrong after using the mouse wheel to zoom

@jeromeWork just for you I got back to the script with the knowledge I collected from other tools. There is this handy class called SceneView that isn’t documented, but you can do quite a lot with it. Here is how the tool looks now:
AnchoredUglyGallinule

And here is the code:

Have fun :slight_smile:

4 Likes

A super little tool. Works brilliantly. Thank you @Johannski ! :slight_smile:

Happy it helps :slight_smile:
Btw, just if you missed it, there are also some handy builtin shortcuts:

  • f to focus on the current object (Also used in the video, not always the result you might want).
  • Mouse wheel click to focus on the point the mouse clicked (kind of like the focus near button in my script, but more flexible).

oooh… Mouse wheel click to focus on click point is new to me! thanks again :smile:

Sadly … doesn’t work with 2019.x (seems Unity changed SceneView class in incompatible ways again :(, removing essential functionality)