Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Join us on Thursday, June 8, for a Q&A with Unity's Content Pipeline group here on the forum, and on the Unity Discord, and discuss topics around Content Build, Import Workflows, Asset Database, and Addressables!
    Dismiss Notice

Matching scene view with Camera View?

Discussion in 'Editor & General Support' started by Shadowing, Apr 9, 2018.

  1. Shadowing

    Shadowing

    Joined:
    Jan 29, 2015
    Posts:
    1,619
    Is there a simple way to make my scene view match my Main camera view?
    if not that would be super useful when working on scenes where your camera doesn't move.
     
    dleight, DaPhantomForce and Tymianek like this.
  2. OneManBandGames

    OneManBandGames

    Joined:
    Dec 7, 2014
    Posts:
    207
    You can align your scene view camera to your game camera: Select your game camera object in the hierarchy, and use GameObject > Align View To Selected from the Unity Editor Menu.
    However that only takes care of alignment, your scene view might still look different due to Projection Size, clipping planes, etc.
    I'm not 100% sure if you can fix this via an Editor Script, but the last answer on this thread looks promising: https://answers.unity.com/questions...itor-camera.html?page=2&pageSize=5&sort=votes

    If I understand it correctly, this approach would allow you to access the camera object that is rendering your scene view, so you could copy all your game camera parameters 1:1 in a script, then your scene view should look exactly the same.
     
  3. Pixasso

    Pixasso

    Joined:
    Mar 4, 2020
    Posts:
    1
    I found a few quick methods to help out with this question as it was something that I was recently looking for myself. The methods follow below (Mac & PC-friendly options). I hope that they help anyone looking for this same info…

    1. Key Command Method - While selecting your camera within the Hierarchy press the following keys:
    a. Mac = Command + Shift + F
    b. PC = Control + Shift + F

    2. Main Navigation Option - While having your main camera selected navigate to the applications main menu:
    GameObject > Align With View
     
  4. nakoustix

    nakoustix

    Joined:
    Apr 21, 2019
    Posts:
    8
    perfect! thank you very much! I wasn't aware of this command and when I, for myself, stumbled across @OP's problem, your input was very helpful.
     
    AliceWasNeverHere and Nubees like this.
  5. FaffyWaffles

    FaffyWaffles

    Joined:
    Apr 10, 2020
    Posts:
    44
    Code (CSharp):
    1. using UnityEngine;
    2. using UnityEditor;
    3.  
    4. [ExecuteInEditMode]
    5. public class AlignCam : MonoBehaviour
    6. {
    7.     public Camera gameCam;
    8.     public bool updateView = false;
    9.     private void LateUpdate()
    10.     {
    11.         if (updateView)
    12.         {
    13.             SceneView sceneCam = SceneView.lastActiveSceneView;
    14.             gameCam.transform.position = sceneCam.camera.transform.position;
    15.             gameCam.transform.rotation = sceneCam.camera.transform.rotation;
    16.         }
    17.     }
    18. }
     
    Lars-Steenhoff likes this.
  6. Metalsoul

    Metalsoul

    Joined:
    Jul 15, 2013
    Posts:
    2
    Expanding on @FaffyWaffles 's (great name btw) solution, here is what I ended up creating:

    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4. using UnityEditor;
    5.  
    6. [CustomEditor(typeof(Camera))]
    7. public class CameraAligner : Editor {
    8.     private Camera camera;
    9.  
    10.     private void OnEnable() {
    11.         camera = (Camera)target;
    12.     }
    13.  
    14.     public override void OnInspectorGUI() {
    15.         if (GUILayout.Button("Align with editor view")) {
    16.             SceneView sceneCam = SceneView.lastActiveSceneView;
    17.             camera.transform.position = sceneCam.camera.transform.position;
    18.             camera.transform.rotation = sceneCam.camera.transform.rotation;
    19.         }
    20.         base.OnInspectorGUI();
    21.     }
    22. }
    This way I can choose a view with the editor and then align the selected camera.
     
    FaffyWaffles likes this.
  7. Le_Jo

    Le_Jo

    Joined:
    Jan 24, 2019
    Posts:
    12
    Great ! Thanks a lot ♥