Editor Camera

How can I spawn a GameObject let’s say, right in the fron of the Editor Camera(the one that is rendering the scene preview on Editor).

If I could get the editor camera it would be easy(camera.transform.position+(camera.transform.forward*10)), but i can’t find a way to do it.

Thanks

Camera.current is how you access the camera that is currently rendering, I think that is what you are lookin’ for.

I’ve tryed Camera.current but it gives me a NullReference Exception.

I have found that you can access the Scene view and the associated camera via the UnityEditor namespace:

Camera cam = UnityEditor.SceneView.lastActiveSceneView.camera;

// But this breaks Unity
cam.orthographic = true;

I tried to set the cam.orthographic property but when doing so, Unity3D started to issues errors to the console and I had to restart it. I am not complaining because the UnityEditor.SceneView property is an undocumented feature and therefore not meant for production use.

Nevertheless accessing the camera position should be save and you might give it a try.

1 Like

Thanks, it did the trick!!