Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
12 Jun 22 - 14 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
1
Question by Der_Kevin · Feb 10, 2016 at 11:18 AM · pathfindinglinegizmodrawline

Gizmos.DrawLine - thickens?

Hey, i am somehow having problems to see a Gizmos.DrawLine in my editor (for debugging) is there a way to let the line appear thicker?, so at the moment its just this:

 Gizmos.color = new Color (0,1F,0,1F);
 
         if (lastCompletedVectorPath != null) {
             for (int i=0;i<lastCompletedVectorPath.Count-1;i++) {
                 Gizmos.DrawLine (lastCompletedVectorPath[i],lastCompletedVectorPath[i+1]);
             }
         }
Comment
Add comment
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

5 Replies

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

Answer by Bunny83 · Feb 10, 2016 at 12:46 PM

Unfortunately Unity doesn't allow to change the line width. So lines drawn are always one pixel lines.

You can either:

  • Draw multiple lines in parallel slightly offset.

  • Draw actual quads instead of lines. However this has to be done with the GL class manually.

For simple debugging it's easier to draw multiple lines. You can create a helper method like this:

 public static void DrawLine(Vector3 p1, Vector3 p2, float width)
 {
     int count = Mathf.CeilToInt(width); // how many lines are needed.
     if(count ==1)
         Gizmos.DrawLine(p1,p2);
     else
     {
         Camera c = Camera.current;
         if (c == null)
         {
             Debug.LogError("Camera.current is null")
             return;
         }
         Vector3 v1 = (p2 - p1).normalized; // line direction
         Vector3 v2 = (c.position - p1).normalized; // direction to camera
         Vector3 n = Vector3.Cross(v1,v2); // normal vector
         for(int i = 0; i < count; i++)
         {
             Vector3 o = n* width ((float)i/(count-1) - 0.5f);
             Gizmos.DrawLine(p1+o,p2+o);
         }
     }
 }

I haven't tested this method as i don't have a Unity installation at hand, but it should work.

Comment
Add comment · 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
9

Answer by thepigeonfighter · Sep 21, 2019 at 08:11 PM

Really old question here. In case anyone else needs to do something similar here is an easy way to do it.

 var p1 = startPosition;
 var p2 = endPosition;
 var thickness = 3;
 Handles.DrawBezier(p1,p2,p1,p2, Color.red,null,thickness);

 
Comment
Add comment · Show 1 · 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 Parzival · May 27, 2020 at 02:55 PM 0
Share

This is awesome. Thank you!

avatar image
1

Answer by jozhard · Mar 22, 2019 at 11:32 AM

Bunny83's version didn't work directly, but the idea is good, so I've changed it a bit to work in screen coordinates and now it works better:

 public static void DrawLine(Vector3 p1, Vector3 p2, float width)
 {
     int count = 1 + Mathf.CeilToInt(width); // how many lines are needed.
     if (count == 1)
     {
         Gizmos.DrawLine(p1, p2);
     }
     else
     {
         Camera c = Camera.current;
         if (c == null)
         {
             Debug.LogError("Camera.current is null");
             return;
         }
         var scp1 = c.WorldToScreenPoint(p1);
         var scp2 = c.WorldToScreenPoint(p2);
 
         Vector3 v1 = (scp2 - scp1).normalized; // line direction
         Vector3 n = Vector3.Cross(v1, Vector3.forward); // normal vector
 
         for (int i = 0; i < count; i++)
         {
             Vector3 o = 0.99f * n * width * ((float)i / (count - 1) - 0.5f);
             Vector3 origin = c.ScreenToWorldPoint(scp1 + o);
             Vector3 destiny = c.ScreenToWorldPoint(scp2 + o);
             Gizmos.DrawLine(origin, destiny);
         }
     }
 }

Comment
Add comment · Show 1 · 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 Alex_TNT · Feb 19, 2020 at 09:24 AM 0
Share

Thanks, works perfect.

avatar image
0

Answer by clintonb · Mar 27, 2019 at 06:35 PM

Here is an easy way to draw thick lines in the scene view and on standard cameras in the game view. (Note that I think the 'thickness' is expressed in pixels).

     public static void DrawThickLine(Vector3 start, Vector3 end, float thickness)
     {
         Camera c = Camera.current;
         if (c == null) return;
 
         // Only draw on normal cameras
         if (c.clearFlags == CameraClearFlags.Depth || c.clearFlags == CameraClearFlags.Nothing)
         {
             return;
         }
 
         // Only draw the line when it is the closest thing to the camera
         // (Remove the Z-test code and other objects will not occlude the line.)
         var prevZTest = Handles.zTest;
         Handles.zTest = UnityEngine.Rendering.CompareFunction.LessEqual;
 
         Handles.color = Gizmos.color;
         Handles.DrawAAPolyLine(thickness * 10, new Vector3[] { start, end });
 
         Handles.zTest = prevZTest;
     }

Comment
Add comment · 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
0

Answer by atorstling · Aug 01, 2021 at 11:47 AM

For those who are trying to adjust circle thickness, here's how. This example is using normals applicable to the 2D case:

 Handles.color = Color.green;
 Handles.DrawWireArc(transform.position, transform.forward, transform.right, 360, 0.2f, 2.0f);

Comment
Add comment · 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

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

41 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 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 avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Confusion with Gizmo Matrix when using Gizmo Cube 2 Answers

OnDrag Draw Line For Pathfinding... 1 Answer

Path Object Is Going To Travel 1 Answer

Draw NavMesh path with multiple points set 0 Answers

Which Gizmo is Debug.DrawLine? 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