- Home /
Choosing which camera draws gizmos
I have two cameras set up, one in orthographic and one in perspective (making a 2D platformer and doing this to get parallax 'for free') and I noticed an interesting effect.
I am drawing a spline using onDrawGizmo() in order to define paths, but both cameras draw the gizmo in a different place due to being in different projection modes. My question is, can you disable drawing gizmos on a per camera basis?
@save answers your last question, but in your specific case I would recommend to use camera.orthographic to check if the camera is in orthographic mode. Which would give:
function OnDrawGizmos () {
if (Camera.current.orthographic) {
// draw something
}
}
Since it doesn't answer the title question, I put it as a comment.
Answer by save · Aug 14, 2013 at 07:27 PM
Sure you can! You just have to restrain it in the actual OnDrawGizmos function. Hopefully there will be a more accessible way in a later version of Unity (4.2+).
var gizmoCamera : Camera; // Choose your Gizmo Camera from the Inspector
function OnDrawGizmos () {
if (Application.isEditor)
if (Camera.current==gizmoCamera || Camera.current==SceneView.lastActiveSceneView.camera)
Gizmos.DrawSphere (transform.position, 1);
}
Brilliant, thanks. Couldn't find any reference in the script reference. $$anonymous$$akes sense as soon as you see it. Thank you
Do you, perchance know if there is a way to make it draw in the scene view? It fixed the issue for the Game view, but now it wont draw in scene view.
I am coding round it by referencing the cameras I DONT want it to draw on. But not ideal
Ah yes sorry, you can access the SceneView class (which is undocumented). Add this to the if-statement:
if (Camera.current==gizmoCamera || Camera.current==SceneView.lastActiveSceneView.camera)
Your answer
Follow this Question
Related Questions
Set Camera icon per script 0 Answers
OnDrawGizmos() called in editor without Start()? 4 Answers
OnDrawGizmos for parent and child class 1 Answer
Constantly Update Scene View 1 Answer
OnDrawGizmos from EditorWindow 1 Answer