Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

SceneView and Camera forward

Discussion in 'Scripting' started by Phantom_X, Feb 26, 2020.

  1. Phantom_X

    Phantom_X

    Joined:
    Jul 11, 2013
    Posts:
    313
    Hi,
    I'm passing the camera forward to VFX graph with a C# script to do some particle alignment. While it's working fine in the game view, the scene view is not correct because it's not the same camera forward.

    I found that I can get the scene view camera with that:
    SceneView.lastActiveSceneView.camera

    but then if I use this, the game view is not ok. My question is, is there a way to detect if the rendering is done in the scene view or game view and pick the right camera forward accordingly?

    Thanks!
     
  2. Yoreki

    Yoreki

    Joined:
    Apr 10, 2019
    Posts:
    2,605
    I didnt try this, but i believe you can get the focussed window through the editor:
    https://docs.unity3d.com/ScriptReference/EditorWindow-focusedWindow.html
    You could then, probably, differentiate between game and scene view and pick the correct camera. You'd need to save the last scene-vs-game view yourself, since other windows can also be focussed, like the inspector. However, you would need to do so in an #if UNITY_EDITOR condition, since otherwise i dont know what would happen when you build it.

    All in all i would probably use the main camera (not scene view) and live with it. After all, scene view is mostly for debugging and development purposes, so seeing things as they are actually being rendered in the scene is a plus point for me.
     
  3. Phantom_X

    Phantom_X

    Joined:
    Jul 11, 2013
    Posts:
    313
    Yes that would be something to do only #if UNITY_EDITOR and is really only for a quality of life improvement I don't want to go too crazy with that, but if there was an easy if() statement that could handle it I would take it ^_^