Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
2
Question by Ianson · Aug 14, 2013 at 07:15 PM · ondrawgizmos

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?

Comment
Add comment · Show 1
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image huulong · Oct 05, 2016 at 12:19 PM 0
Share

@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.

1 Reply

· Add your reply
  • Sort: 
avatar image
2
Best Answer

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);
 }
Comment
Add comment · Show 8 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Ianson · Aug 14, 2013 at 07:33 PM 1
Share

Brilliant, thanks. Couldn't find any reference in the script reference. $$anonymous$$akes sense as soon as you see it. Thank you

avatar image save · Aug 14, 2013 at 07:42 PM 0
Share

Perfect! Glad it worked out.

avatar image Ianson · Aug 14, 2013 at 07:44 PM 0
Share

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.

avatar image Ianson · Aug 14, 2013 at 07:57 PM 0
Share

I am coding round it by referencing the cameras I DONT want it to draw on. But not ideal

avatar image save · Aug 14, 2013 at 08:08 PM 0
Share

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)
Show more comments

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

17 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

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


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges