Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
2 captures
13 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
2
Question by medyahan · May 06, 2021 at 09:57 AM · meshpositionverticesvertexmeshfilter

Why vertex positions appear (0.0, 0.0, 0.0) ?

Hello. I print it in the code to see the locations of the vertexes in my hair object. But it is written as the position of all vertexes on the console (0.0, 0.0, 0.0). it shouldn't be like this. What could be the problem? Thanks in advance..

 void Start()
      {
          meshfilter = GetComponent<MeshFilter>();
          hairMesh = meshfilter.mesh;
          verts = hairMesh.vertices;
  
          foreach (var vert in verts)
          {
              Debug.Log(vert);
          }
      }
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 DenisIsDenis · May 06, 2021 at 11:10 AM 0
Share

I tested your code on a simple cube and the vertex coordinates are displayed correctly in the console.

vertices of the cube

vertices-of-the-cube.png (23.5 kB)

1 Reply

· Add your reply
  • Sort: 
avatar image
1

Answer by andrew-lukasik · May 06, 2021 at 11:14 AM

Rounding. Try:

 Debug.Log($"( {vert.x:G9} , {vert.y:G9} , {vert.z:G9} )");

Edit: Replaced G17 with G9, as that's enough for floats. G17 is better suited for double.

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 Bunny83 · May 06, 2021 at 12:50 PM 1
Share

Note that Vector3 has an ToString version that takes a format descriptor. So you can simply do

 Debug.Log(vert.ToString("G17"));

Just to clarify: By default the ToString method of the Vector3 type does round the components to 1 decimal place. So relatively small numbers would all round down to 0. Also keep in $$anonymous$$d that the vertices are specified in local space, not worldspace. So moving, rotating or scaling the object does not change the vertices.


Finally be careful when using the mesh property of the MeshFilter component as it will duplicate the mesh for this instance. If you just want to read the vertices, you should access the "sharedMesh" instead.


pps: I forgot to mention that in order to read the vertices of an imported mesh, that mesh need to be imported with read / write support enabled. If you did not do that explicitly, the mesh only exists in the GPU memory and you don't have access to the vertices.

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

157 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 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 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 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

Getting the world position of mesh vertices? 2 Answers

Creating a mesh for an overview map 0 Answers

Mesh.vertices are all 0? 1 Answer

UnityEngine.UI.Text characters mesh 0 Answers

Editing vertices 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