Search Unity

Camera aspect not adjusted when using PreviewRenderUtility [possible bug]

Discussion in 'Immediate Mode GUI (IMGUI)' started by gilley033, Mar 1, 2019.

  1. gilley033

    gilley033

    Joined:
    Jul 10, 2012
    Posts:
    1,191
    I am attempting to create an editor window that mimics some of the Scene Views functionality. This editor window is used to edit a pattern in an intuitive way.

    To do this, I am utilizing PreviewRenderUtility, which is working great. However, there is one issue. I need to make use of Handles, which I have done. When the window is very large the position of the handles lines up correctly, but if I resize the editor window's width, the handles fall out of alignment.

    I know why this is happening. In the scene view, when you adjust the width or height of the scene view window, the scene camera's aspect (or it might be its field of view) is automatically adjusted. So you will see the objects in the scene view get bigger or larger when you adjust the scene view size.

    However, for my editor window, the aspect (or again, it maybe the FOV, I'm not really sure), is only adjusted when the editor window height is changed.

    Here's what it looks like:



    Basically, I need the behaviour that occurs when the window's height is changed to also be the behaviour that occurs when the window's width is changed. This is how it works with the Scene View window and I am not sure why it doesn't work in this case. Here is the code:

    Code (CSharp):
    1. var pos = new Rect(0, 0, position.width, position.height);
    2.            
    3. preview.BeginPreview(pos, EditorStyles.helpBox);
    4. preview.Render();
    5. preview.EndAndDrawPreview(pos);
    6. DrawWindow();
    7.  
    8. Handles.SetCamera(sceneCamera);
    where position is the position of the editor window.
     
  2. Madgvox

    Madgvox

    Joined:
    Apr 13, 2014
    Posts:
    1,317
    Send a bug report if you have not already, let the unity team check it out.
     
  3. gilley033

    gilley033

    Joined:
    Jul 10, 2012
    Posts:
    1,191
    Good idea; bug submitted. 1132779_0lcmbpjup0rm77b9
     
  4. gilley033

    gilley033

    Joined:
    Jul 10, 2012
    Posts:
    1,191
    Bug was reproduced and is being sent for resolution with Unity developers. Will update this thread with the patch or version number when it's fixed.
     
  5. gilley033

    gilley033

    Joined:
    Jul 10, 2012
    Posts:
    1,191
    I just want to add that this bug seems to effect Event.mousePosition as well, as I get some inaccuracy when utilizing the HandleUtility.PickGameObject method which I can only attribute to a whacky mousePosition.
     
  6. gilley033

    gilley033

    Joined:
    Jul 10, 2012
    Posts:
    1,191
    Is there a work around for this? I'm not sure if the fix, when published, will be patched into older versions of Unity (which I need to support), and this is being used on an Asset Store product. I'd really rather not force the user to expand the editor window to its maximum width just to be able to use my tool . . .
     
  7. gilley033

    gilley033

    Joined:
    Jul 10, 2012
    Posts:
    1,191
    Bumping this question. I am trying to search through the source code to determine what exactly controls the positioning of handles, but everything defaults to internal code at the end so I am unable to pinpoint it.

    Are there any developers that can provide some advice?