• 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 rcg · Apr 13, 2011 at 03:13 AM · meshproceduralvertices

reading vertices from a mesh always returns Vector3.zero

I'm trying to read the vertices from a mesh that I've imported into my scene from an fbx file.

Something like this:

public MeshFilter MyMesh;
.
.
.
    for (int i=0; i<MyMesh.sharedMesh.vertices.Length; i++)
    {
        Debug.Log("Vertex #"+i + " "+MyMesh.sharedMesh.vertices[i]);
    }

The mesh renders fine in the scene, and I print the correct number of vertices, but they always come out as (0,0,0).

Any ideas what I'm doing wrong?

Thanks.

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

2 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by rcg · Apr 13, 2011 at 04:24 AM

In the interest of making up for my stupid question I'll post what ended up being the real problem, and the solution I found for it (although I'm still not sure why the solution was necessary).

I was trying to create a SkinnedMeshRenderer from a mesh template imported from an fbx file. I have hundreds of these in my scene, and to try and improve performance I wanted to procedurally generate a skinned mesh with one bone for each instance of the template I wanted in the scene.

I was following the example here:

http://unity3d.com/support/documentation/ScriptReference/Mesh-bindposes.html?from=SkinnedMeshRenderer

But when I tried to do the following:

Mesh mesh = new Mesh();
mesh.vertices = new Vector3[TileMesh.sharedMesh.vertices.Length];
for (int i=0; i<TileMesh.sharedMesh.vertices.Length; i++)
{
    mesh.vertices[i] = TileMesh.sharedMesh.vertices[i];
}

The values in mesh.vertices remained (0,0,0).

For whatever reason this (below) ended up working and fixing my problem. Perhaps it's because mesh.vertices is a read only property, I don't know. If that was the case I would have expected a compile error...but it's working now so I'm happy.

Mesh mesh = new Mesh();
Vector3 [] vertices = new Vector3[TileMesh.sharedMesh.vertices.Length];
for (int i=0; i<TileMesh.sharedMesh.vertices.Length; i++)
{
    vertices[i] = TileMesh.sharedMesh.vertices[i];
}
mesh.vertices = vertices;

Still curious why I had to do this, but maybe this will help someone else in the future.

Comment
Add comment · Show 2 · 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 Eric5h5 · Apr 13, 2011 at 04:59 AM 0
Share

The docs for the $$anonymous$$esh class actually tell you to do that, and as the $$anonymous$$esh.vertices docs say, it returns a copy of the vertices. In other words, it's not a reference to the actual vertices (probably because it has to be uploaded to VRA$$anonymous$$ when you assign it back).

avatar image rcg · Apr 13, 2011 at 05:37 AM 0
Share

Thanks for the info.

avatar image
1

Answer by rcg · Apr 13, 2011 at 03:46 AM

OK, I'm an idiot...great first post :) The sizes were smaller than the precision of the Vector3 string printing. Doesn't solve my real problem, but gets me past this false alarm. nothing to see here...

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.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

No one has followed this question yet.

Related Questions

Generate mesh from raycast positions, independent of rotations 0 Answers

Do I need to split my mesh up to properly UV texture it? 1 Answer

How do you scale a sphere or object by 2x using Mesh.vertices 2 Answers

MeshCollider is not getting updated when adding vertex to mesh 1 Answer

Procedural Mesh Generation - Split Arrays into sections 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