- Home /
Camera.Render assertion in EditorWindow's OnGUI
I am trying to make an EditorWindow that displays the current scene with a camera, preferably without the use of RenderTextures, as that is a pro only feature, (and because if I were using raw OpenGL, that isn't the way I would do it as it would seem to be a waste of texture memory if there is an already existing frame buffer that I want to be drawing into anyway)
So I created an EditorWindow subclass called LevelEditor, from which I just took the small relevant snippet.
public class LevelEditor : EditorWindow
{
public Camera cam;
void OnGUI()
{
cam.pixelRect = new Rect(0, 0, position.width, position.height);
cam.Render();
GUILayout.Label("Hello World", skin.label);
}
}
I set cam in the inspector to be a camera separate from the main camera, and this EditorWindow will now draw the scene from the point of view of that camera.
However, while most of the time this works perfectly, (and quite quickly), sometimes it starts spraying out assertions inside the cam.Render(). Sometimes it sprays out 100 assertions in a frame, causing several seconds of lag between frames.
The assertion I get is screenviewcoord[1] < 0 || screenviewcoord[3] < 0 UnityEngine.Camera:Render() LevelEditor:OnGUI() (at Assets/Editor/LevelEditor.cs:32) UnityEditor.DockArea:OnGUI()
I believe this assertion is stating that the viewport I have set for the window does not actually fit inside the window I am drawing to, and based on the fact it only happens sometimes (and more and more often the larger the size of the EditorWindow), I expect that it is occurring as a race condition in which either the viewport I am sending or the window I am drawing to is changing during the Render() call.
Is there any function I can call to prevent Unity from trying to draw another window while I am rendering?
Is there any function I can call to set the window to draw to as my EditorWindow from inside my EditorWindow's Update() call, so that I can move my cam.Render there, where I may be less likely to run into threading issues?
Has anyone successfully done this before?
Your answer
Follow this Question
Related Questions
Am I over-engineering my editorscript? 0 Answers
How do I get the properties of a model's (or Camera's) Transform in the Editor Preview control? 0 Answers
Adjust the width/height of List property elements in the Inspector 1 Answer
I am making a level editor and need ideas on how to save the level file. 1 Answer