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 vexe · Dec 15, 2013 at 02:28 PM · gizmo

Gizmos.DrawSphere with a radius not known beforehand (not a constant)?

I have a simple custom plane object with a Height and a Width properties. I want to draw a sphere, that will cover the plane object so I have to figure out if Height is greater than Width or it's the opposite to determine the radius. In other words, I'm not passing a constant - I'm passing a value, that requires some logic to be done before hand to be done first, to get the right value. I did this, and I didn't get any visuals:

 private void OnDrawGizmosSelected()
 {
     Gizmos.color = Color.red;
     Gizmos.DrawWireSphere(transform.position, Mathf.Max(Width, Height));
 }

Of course if I explicitly tell it the radius (give it a constant) - it works.

Is there a way to do what I want? or this is just how it works? (the radius has to be a constant)

I tried sticking [ExecuteInEditMode] (doesn't make so much sense but just a try) - it didn't do anything.

Any ideas?

Thanks.

Comment
Add comment · Show 2
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 KellyThomas · Dec 15, 2013 at 03:32 PM 0
Share

Are Width, Height and the return value from $$anonymous$$ax() all sane values?

avatar image vexe · Dec 15, 2013 at 04:06 PM 0
Share

Sorry, sane values? did you mean scene values? - in either cases, didn't get what you mean.

1 Reply

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

Answer by KellyThomas · Dec 15, 2013 at 10:29 PM

The DrawWireSphere() call works when you pass a literal value, so the issue may with the value returned by Max().

I recommend checking to see that all involved values are in the range that you are expecting i.e. a sanity check. Something like this would do.

 using System;
 
 // ....

 float max = Mathf.Max(Width, Height);
 Debug.Log(String.Format("Width: {0}, Height: {1}, Max:{2}", Width, Height, max));
 Gizmos.DrawWireSphere(transform.position, max)
 
Comment
Add comment · Show 4 · 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 vexe · Dec 15, 2013 at 11:09 PM 0
Share

Although I'm not really convinced as to why this works, but it does... The values are fine I just had to use a float max variable that takes the return value from $$anonymous$$ax, and use the variable ins$$anonymous$$d.

avatar image KellyThomas · Dec 15, 2013 at 11:39 PM 0
Share

I just tried to reproduce the issue but my gizmo was drawing on all occasions. Odd behaviour...

avatar image vexe · Dec 15, 2013 at 11:51 PM 0
Share

Well... I forgot to mention that Height and Width are properties. I didn't think it would make a difference, but it seems it does. I just passed in $$anonymous$$ax(x, y) where x, y are just normal variables, it worked....

avatar image vexe · Dec 15, 2013 at 11:52 PM 0
Share

I also just tried passing GetX() and GetY() as $$anonymous$$ax's parameters. Works. Very strange...

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

Can we hide AudioSource gizmos? 4 Answers

DrawGizmo attribute: GizmoType arg with incompatible flag values 0 Answers

Children's collider2D gizmo position incorrect in scene view 0 Answers

Custom inspector draw Gizmos 0 Answers

Colide objects with runtime gizmo movement 0 Answers


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