x


How to get access to the editor camera?

Hello,

I'd like to write an editor script that forces the scene view camera (in the editor) to follow an object as it moves while the game is playing (Like the player). How can I get access to the editor camera so that I can do this?

more ▼

asked May 18 '10 at 09:03 PM

Robert 1 gravatar image

Robert 1
364 17 18 25

(comments are locked)
10|3000 characters needed characters left

3 answers: sort voted first

This thread should give you the information you need:

http://forum.unity3d.com/viewtopic.php?t=33679

Basically, you can get the scene camera with Camera.current, but you NEED to check if it's null, since that variable is only available when the Scene view has focus, otherwise it will be null.

I'm not sure how much you can modify the Scene camera, either... I've heard mixed reports in the past. I've heard you can't really change how the camera behaves very much, but I've also seen some editor scripts that (claim to) modify it, so if something isn't working for you, it might just not be possible.

more ▼

answered May 18 '10 at 09:08 PM

qJake gravatar image

qJake
11.6k 43 78 161

Thanks. If it's null while the scene view does not have focus then this won't work for me. I need it to follow while I play the game. However, you did answer my question!

May 18 '10 at 09:18 PM Robert 1

Then I don't know if what you want is possible... you could wait to see if someone else responds here, or ask on the forums if you need it that badly. :P

May 18 '10 at 09:28 PM qJake

Bob, perhaps you could save what camera you are referencing when the scene does have focus, and then use that reference later? I'm atm trying to do something similar myself, don't know if it'll work. Think of it like this: I open my custom editor window. Editor window keeps trying to assign a camera - if null, retry. I click on the scene view. Camera get's assigned. I click outside, but the reference is kept.

May 05 '11 at 01:43 PM Joshua
(comments are locked)
10|3000 characters needed characters left

I had the same issue and wrote a script that follows the specified target transform. It even works for multiple SceneViews. It's on Unity3D's wiki now: http://wiki.unity3d.com/index.php/SceneViewCameraFollower Hope it helps.

more ▼

answered Oct 21 '12 at 05:33 AM

Lttldude gravatar image

Lttldude
1.2k 1 2 7

(comments are locked)
10|3000 characters needed characters left

There is another way to accomplish this using the (undocumented) UnityEngine.SceneView interface. While there is no way to directly set the current scene view camera's transform, there's a handy AlignViewToObject call (identical to the GameObject menu item). Here's some C# trickery:

var view = SceneView.currentDrawingSceneView;
if(view != null)
{
    var target = new GameObject();
    target.transform.position = NewCameraPosition;
    target.transform.rotation = NewCameraRotation;
    view.AlignViewToObject(target.transform);
    GameObject.DestroyImmediate(target);
}

I use this general strategy in a number of ways to make scene navigation less painful for myself, but you can probably see how it might be altered to suit your needs (e.g. since you are updating the camera every frame, it probably makes sense to keep a persistent dummy object around for alignment, rather than creating and destroying one each time).

Hope this helps!

more ▼

answered May 24 '12 at 04:04 PM

chomp gravatar image

chomp
0 1

(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x3014
x1677

asked: May 18 '10 at 09:03 PM

Seen: 4249 times

Last Updated: Oct 21 '12 at 05:33 AM