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
0
Question by yellowelephant · Aug 13, 2014 at 01:09 AM · animationtransformvertex

Vertex transformation - MissingFieldException error

I'm getting MissingFieldException: UnityEngine.Vector3.transform when trying to use a script. I don't know whats wrong with it and it's frustating me.

     function Update () {
     var mesh : Mesh = GetComponent(MeshFilter).mesh;
     var vertices : Vector3[] = mesh.vertices;
     var normals : Vector3[] = mesh.normals;
     for (var i = 0; i < vertices.Length; i++)
     vertices[i].transform.position = vertices[i].transform.position + Vector3(0,Random.Range(-1,1),0);
     mesh.vertices = vertices;
     }

Can somebody help me ?

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
Best Answer

Answer by robertbu · Aug 13, 2014 at 01:11 AM

Vertices in a mesh are Vector3 objects. Vector3s don't have a transform or a position. To move one you would do:

 vertices[i] +=  Vector3(0,Random.Range(-1.0,1.0),0);

Note that your original code had integers in the Random.Range(), so the code would only have returned values -1 and 0 (since the integer version of Random.Range() is exclusive of the final value passed). I changed it to use floats.

Comment
Add comment · Show 3 · 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 yellowelephant · Aug 13, 2014 at 01:13 AM 0
Share

Thank you so much!

avatar image WhoRainZone1 · Aug 13, 2014 at 01:16 AM 0
Share

Just nitpicking, but actually you are now using doubles. Type 1.0f to get floats - but it shouldn't make a big difference as you don't have any decimal value given anyway.

avatar image robertbu · Aug 13, 2014 at 01:18 AM 0
Share

Nope, not doubles. The use of 'function' in his code above indicates that he is using Javascript. Decimal numbers are floats by default in Javascript. It is C# that has doubles by default. And you'd need a 'new' operator in front of 'Vector3' for C#.

avatar image
0

Answer by WhoRainZone1 · Aug 13, 2014 at 01:14 AM

Only GameObjects do have transform, your vector array doesnt, as it is no GameObject.

 vertices[i] += Vector3(0,Random.Range(-1,1),0);

This should work. But why? Because you are now using the vector's values, instead of trying to access something that isn't even there.

Cheers, WRZ

edit: oops, too slow :)

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

3 People are following this question.

avatar image avatar image avatar image

Related Questions

Converting Mesh to Set of Discrete Coordinates 1 Answer

Can I make animations snap to a frame? 1 Answer

Possible to transform and objects position smoothly with confined movement dictated by raycasting, but controlled by user? 0 Answers

hypercube animation 2 Answers

Rotating An Object On Its Axis Once 3 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