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
0
Question by mellooow9 · May 02, 2020 at 03:01 AM · meshverticesvertexmeshfiltersharedmesh

Mesh.vertices are all 0?

I made this mesh in blender, and imported it into unity as an fbx. The vertices array has a bunch of verts on it, but they are all 0, 0, 0.

 private void OnGUI()
     {
         
 
         if (GUILayout.Button("test")) {
 
            plane = GameObject.Find("testPlane");
             
             mesh=plane.GetComponent<MeshFilter>().sharedMesh;
             
 
             for (int i=0; i<mesh.vertices.Length; i++) {Debug.Log(mesh.vertices[i]); }
 
 
             }



Why would it be doing this?

Also this is an editor script in the editor folder.

 public class editorTest : EditorWindow
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

1 Reply

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

Answer by Bunny83 · May 02, 2020 at 10:50 AM

First and foremost never ever execute such a loop -.-

Each time you read the vertices property of the mesh class you will create a new copy of the vertices array and the vertices are copied from native code into the managed code array. Currently you create a new copy of your vertices array two times each iteration. So always cache that array:


Your next issue could be that since the default ToString override of Vector3 rounds the output to 1 decimal place you might not see your actual numbers if you created a very small mesh. This could easily happen when you imported the mesh with a very small scaling factor. So try printing the vectors with a higher precision. "F7" should be enough for most cases.


 mesh=plane.GetComponent<MeshFilter>().sharedMesh;
 var vertices = mesh.vertices; // read it once
 for (int i=0; i < vertices.Length; i++)
 {
     Debug.Log("Vertex #"+i+" = " + vertices[i].ToString("F7"));
 }



If they are still all (0, 0, 0), do you actually see the mesh in the scene? How large does it appear in the scene? When click on the mesh field of the MeshFilter in the inspector, Unity should highlight the actual source mesh in the project so you can inspect the actual mesh and see its stats in the inspector. How many vertices / triangles does the mesh have?

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 mellooow9 · May 02, 2020 at 09:08 PM 0
Share

Thanks, the verts weren't exactly 0, but were really small numbers. It was because my fbx had 100 scale on it. I got the scale to 1 and everything is working now.

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

139 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

Related Questions

Creating a mesh for an overview map 0 Answers

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

Can't change verts on mesh after assigning to meshfilter. 1 Answer

Number of mesh vertices increase when imported into unity 1 Answer

Procedural Mesh problem from Editor Window 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