# Unity3d Editor camera

**URL:** <https://discussions.unity.com/t/unity3d-editor-camera/399310>\
**Category:** Camera\
**Tags:** Scripting\
**Created:** [October 8, 2009, 4:52am UTC](https://discussions.unity.com/t/unity3d-editor-camera/399310 "2009-10-08T04:52:13Z")\
**Posts on this page:** 17\
**Page:** 1

<div class="post-metadata">

**Author:** ![roychr](https://dub1.discourse-cdn.com/unity/user_avatar/discussions.unity.com/roychr/32/142382_2.png) [@roychr](https://discussions.unity.com/u/roychr)\
**Post date:** [October 8, 2009, 4:52am UTC](https://discussions.unity.com/t/unity3d-editor-camera/399310/1 "2009-10-08T04:52:13Z")

</div>

Hi,

I searched the forum, maybe this information is old or burried somewhere deep in the forum. Well in any cases I would happily like to know if i can get the camera in the unity3d editor in #scene mode. I am doing pathfinding placement and as you could guess drawing gizmos at each 1 Unit on a 100x100 map can slow the editor down. I added a show variable to disable all gizmos. But it would be better for me to test the distance for the said Node from the camera distance, if its less than for example 20 units, draw it. This would greatly improve visual cues speed for me.  
 ![](http://x9productions.com/files/blog/graph.PNG)

---

<div class="post-metadata">

**Author:** ![andeeeee](https://avatars.discourse-cdn.com/v4/letter/a/51bf81/32.png) [@andeeeee](https://discussions.unity.com/u/andeeeee)\
**Post date:** [October 8, 2009, 1:46pm UTC](https://discussions.unity.com/t/unity3d-editor-camera/399310/2 "2009-10-08T13:46:53Z")

</div>

I don’t think there is any way to get the position of the Scene view camera. Also, I know you were trying to give the impression of scale, but it is much better if you don’t add large images to your posts - it’s a nuisance to read when you have to keep scrolling horizontally.

---

<div class="post-metadata">

**Author:** ![roychr](https://dub1.discourse-cdn.com/unity/user_avatar/discussions.unity.com/roychr/32/142382_2.png) [@roychr](https://discussions.unity.com/u/roychr)\
**Post date:** [October 8, 2009, 2:30pm UTC](https://discussions.unity.com/t/unity3d-editor-camera/399310/3 "2009-10-08T14:30:31Z")

</div>

Sorry for the image size, fixed it. Still searching for some answer for this any Unity dev can answer this quickly please ?

---

<div class="post-metadata">

**Author:** ![Martin-Schultz](https://dub1.discourse-cdn.com/unity/user_avatar/discussions.unity.com/martin-schultz/32/572373_2.png) [@Martin-Schultz](https://discussions.unity.com/u/Martin-Schultz)\
**Post date:** [October 8, 2009, 2:38pm UTC](https://discussions.unity.com/t/unity3d-editor-camera/399310/4 "2009-10-08T14:38:35Z")

</div>

Hmm, if I recall right, isn’t in the editor

```auto
Camera.main

```

the game camera and

```auto
Camera.current

```

the editor camera? I _think_ I read this in the docs somewhere.

---

<div class="post-metadata">

**Author:** ![roychr](https://dub1.discourse-cdn.com/unity/user_avatar/discussions.unity.com/roychr/32/142382_2.png) [@roychr](https://discussions.unity.com/u/roychr)\
**Post date:** [October 8, 2009, 3:09pm UTC](https://discussions.unity.com/t/unity3d-editor-camera/399310/5 "2009-10-08T15:09:32Z")

</div>

Those are for runtime. When you use Camera.main, its the first tagged Main Camera camera that you receive.

I used this for testing:

```auto
	@MenuItem("PathFinding/Test")
	static function test()
	{
		var cam:Camera = Camera.main;
		Debug.Log("Camera name is : " + cam.name + " pos: " + cam.transform.position.ToString());
	}

```

So it returns me my camera hierarchy object. Camera.current returns null if used in the above code instead of .main

This is no good i need the editor camera for editor window gizmo culling.

---

<div class="post-metadata">

**Author:** ![Martin-Schultz](https://dub1.discourse-cdn.com/unity/user_avatar/discussions.unity.com/martin-schultz/32/572373_2.png) [@Martin-Schultz](https://discussions.unity.com/u/Martin-Schultz)\
**Post date:** [October 8, 2009, 3:17pm UTC](https://discussions.unity.com/t/unity3d-editor-camera/399310/6 "2009-10-08T15:17:29Z")

</div>

> [@Martin Schultz](#):
>
> Hmm, if I recall right, isn’t in the editor
> 
> ```auto
> Camera.main
> 
> ```
> 
> the game camera and
> 
> ```auto
> Camera.current
> 
> ```
> 
> the editor camera? I _think_ I read this in the docs somewhere.

Ok, found it. I have an editor script here which relies on the editor camera and uses Camera.current to calculate some stuff based on the editor camera (which is then Camera.current):

```auto
public class TrackNodeMenuItem : MonoBehaviour {

	[MenuItem("GameObject/Create Track Node")]

	static void CreateTrackNode() {	
		
		// Cast ray to find position to place the track node
		RaycastHit hit = new RaycastHit();
		Transform cameraTransform = Camera.current.transform;
		Vector3 fwd = cameraTransform.TransformDirection(Vector3.forward);

```

---

<div class="post-metadata">

**Author:** ![roychr](https://dub1.discourse-cdn.com/unity/user_avatar/discussions.unity.com/roychr/32/142382_2.png) [@roychr](https://discussions.unity.com/u/roychr)\
**Post date:** [October 8, 2009, 3:32pm UTC](https://discussions.unity.com/t/unity3d-editor-camera/399310/7 "2009-10-08T15:32:35Z")

</div>

Ok thanks Martin,

I really do not know why it does go through with the following now and it did not 15 min. ago ^ ^

```auto
	@MenuItem("PathFinding/Test")
	static function test()
	{
		Debug.Log("Camera name is : " + Camera.current.name + " pos: " + Camera.current.transform.position.ToString());
	}

```

gives the following :

```auto
Camera name is : SceneCamera pos: (2.2, 6.7, 3.9)
UnityEngine.Debug:Log(Object)
PathFindingEditor:test() (at Assets\Editor\PathFindingEditor.js:8)

```

Thanks for helping, guess this was pretty obvious after all !

---

<div class="post-metadata">

**Author:** ![invicticide\_1](https://dub1.discourse-cdn.com/unity/user_avatar/discussions.unity.com/invicticide_1/32/580676_2.png) [@invicticide\_1](https://discussions.unity.com/u/invicticide_1)\
**Post date:** [November 15, 2009, 3:58am UTC](https://discussions.unity.com/t/unity3d-editor-camera/399310/8 "2009-11-15T03:58:32Z")

</div>

> [@""](#):
>
> Ok thanks Martin,
> 
> I really do not know why it does go through with the following now and it did not 15 min. ago ^ ^

FYI…

I stumbled across this thread while trying to figure out this same thing on my own. Some further testing reveals that Camera.current is apparently only valid if a Scene view has focus, and it’ll be the camera for that particular Scene view. If no Scene view has focus (f.ex. you last clicked on the Inspector, or something) then Camera.current will be null.

In my case, I have a menu item creating a GameObject based on the editor camera’s position. It’s annoying to require Scene view focus, especially when I’m using a hotkey and making lots of adjustments in the Inspector… so now I keep a m\_lastUsedCamera around, which I use in case Camera.current comes up null. Whenever Camera.current comes up valid, I update m\_lastUsedCamera to that camera.

Seems to work for all cases so far, except if you start up a fresh editing session and invoke the menu command for the first time without Scene view focus… I’m just printing a warning in that case.

---

<div class="post-metadata">

**Author:** ![anon\_76792142](https://avatars.discourse-cdn.com/v4/letter/a/7ea924/32.png) [@anon\_76792142](https://discussions.unity.com/u/anon_76792142)\
**Post date:** [September 13, 2010, 10:52am UTC](https://discussions.unity.com/t/unity3d-editor-camera/399310/9 "2010-09-13T10:52:50Z")

</div>

Not to resurect an old thread but noticed you were all using Camera.current and getting null.

Try camera.current to get the current camera (Notice no cap C on camera)

---

<div class="post-metadata">

**Author:** ![MattFS](https://dub1.discourse-cdn.com/unity/user_avatar/discussions.unity.com/mattfs/32/127211_2.png) [@MattFS](https://discussions.unity.com/u/MattFS)\
**Post date:** [September 22, 2010, 6:55am UTC](https://discussions.unity.com/t/unity3d-editor-camera/399310/10 "2010-09-22T06:55:08Z")

</div>

There doesn’t seem to be a member _camera_, the only way I can find a lower case one is through Camera.main.camera ?

But still on this subject, has anyone found a way to do this? I’m starting to write more editor scripts and this need starts coming up more and more…

For example, you might simply want a ‘decal projector’ script that uses the editor cam… a ‘select all in view’ using the editor cam, or you might be saving editor positions (like you can in UE3 Editor) in a very large level and want to quickly Get/Set the camera position… etc, etc! 🙂

How can we access that camera considering the problems above that ‘current’ gets set to null if the Scene window isn’t focused?

---

<div class="post-metadata">

**Author:** ![MattFS](https://dub1.discourse-cdn.com/unity/user_avatar/discussions.unity.com/mattfs/32/127211_2.png) [@MattFS](https://discussions.unity.com/u/MattFS)\
**Post date:** [October 17, 2010, 3:12am UTC](https://discussions.unity.com/t/unity3d-editor-camera/399310/11 "2010-10-17T03:12:19Z")

</div>

my projects are still underway with U2.6 so I haven’t check in U3… but is this still a missing ‘feature’?  
Can anyone access the editor camera yet?

---

<div class="post-metadata">

**Author:** ![andeeeee](https://avatars.discourse-cdn.com/v4/letter/a/51bf81/32.png) [@andeeeee](https://discussions.unity.com/u/andeeeee)\
**Post date:** [October 18, 2010, 2:28pm UTC](https://discussions.unity.com/t/unity3d-editor-camera/399310/12 "2010-10-18T14:28:01Z")

</div>

I think the method involving Camera.current (capital C on Camera - it’s a class property) has always worked under “normal” circumstances. Is this not working for you under 2.6?

---

<div class="post-metadata">

**Author:** ![MattFS](https://dub1.discourse-cdn.com/unity/user_avatar/discussions.unity.com/mattfs/32/127211_2.png) [@MattFS](https://discussions.unity.com/u/MattFS)\
**Post date:** [October 19, 2010, 3:58am UTC](https://discussions.unity.com/t/unity3d-editor-camera/399310/13 "2010-10-19T03:58:49Z")

</div>

hey andeee - actually yes that works, sorry i misread the above mentioned camera.current (as the no capital was pointed out! 😛 )  
this does indeed return the Scene view camera though only when it is being rendered (hover the mouse… etc)  
but cool, I’ll work from here then!  
thanks! 🙂

---

<div class="post-metadata">

**Author:** ![Synercoder](https://avatars.discourse-cdn.com/v4/letter/s/848f3c/32.png) [@Synercoder](https://discussions.unity.com/u/Synercoder)\
**Post date:** [May 27, 2013, 12:09pm UTC](https://discussions.unity.com/t/unity3d-editor-camera/399310/14 "2013-05-27T12:09:58Z")

</div>

I create a complete script for the ones still looking:

```auto
using UnityEditor;
using UnityEngine;

public static class SceneCameraMenuItem
{
    private static Camera _sceneCamera = null;

    [MenuItem("Scene/Set camera")]
    public static void SetMainToScene()
    {
        if (Camera.main == null)
        {
            Debug.Log("Main camera not found.");
            return;
        }
        if (_sceneCamera == null)
        {
            if (Camera.current == null || Camera.current.name != "SceneCamera")
            {
                Debug.Log("Scene camera not selected. First click on Scene tab before calling.");
                return;
            }
            _sceneCamera = Camera.current;
        }

        Camera.main.transform.position = _sceneCamera.transform.position;
        Camera.main.transform.rotation = _sceneCamera.transform.rotation;
    }
}

```

---

<div class="post-metadata">

**Author:** ![AngryAnt](https://dub1.discourse-cdn.com/unity/user_avatar/discussions.unity.com/angryant/32/274841_2.png) [@AngryAnt](https://discussions.unity.com/u/AngryAnt)\
**Post date:** [May 27, 2013, 12:53pm UTC](https://discussions.unity.com/t/unity3d-editor-camera/399310/15 "2013-05-27T12:53:25Z")

</div>

Great work, Synercoder, note though that the functionality you seek is actually already available in the default Unity menus.

GameObject → Align With View

and

GameObject → Align View to Selected

> [@Synercoder](#):
>
> I create a complete script for the ones still looking:
> 
> ```auto
> using UnityEditor;
> using UnityEngine;
> 
> public static class SceneCameraMenuItem
> {
> private static Camera _sceneCamera = null;
> 
> [MenuItem("Scene/Set camera")]
> public static void SetMainToScene()
> {
> if (Camera.main == null)
> {
> Debug.Log("Main camera not found.");
> return;
> }
> if (_sceneCamera == null)
> {
> if (Camera.current == null || Camera.current.name != "SceneCamera")
> {
> Debug.Log("Scene camera not selected. First click on Scene tab before calling.");
> return;
> }
> _sceneCamera = Camera.current;
> }
> 
> Camera.main.transform.position = _sceneCamera.transform.position;
> Camera.main.transform.rotation = _sceneCamera.transform.rotation;
> }
> }
> 
> ```

---

<div class="post-metadata">

**Author:** ![Synercoder](https://avatars.discourse-cdn.com/v4/letter/s/848f3c/32.png) [@Synercoder](https://discussions.unity.com/u/Synercoder)\
**Post date:** [May 28, 2013, 9:36am UTC](https://discussions.unity.com/t/unity3d-editor-camera/399310/16 "2013-05-28T09:36:02Z")

</div>

Well, that is what you get when you don’t know the editor… Reinventing the wheel…

> [@AngryAnt](#):
>
> Great work, Synercoder, note though that the functionality you seek is actually already available in the default Unity menus.
> 
> GameObject → Align With View
> 
> and
> 
> GameObject → Align View to Selected

---

<div class="post-metadata">

**Author:** ![Innovative](https://dub1.discourse-cdn.com/unity/user_avatar/discussions.unity.com/innovative/32/190533_2.png) [@Innovative](https://discussions.unity.com/u/Innovative)\
**Post date:** [August 12, 2013, 3:03pm UTC](https://discussions.unity.com/t/unity3d-editor-camera/399310/17 "2013-08-12T15:03:25Z")

</div>

Best solution I’ve found is here at [http://www.olivereberlei.com/517/wrestling-with-the-editor-camera-in-unity/](http://www.olivereberlei.com/517/wrestling-with-the-editor-camera-in-unity/)
