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 cidmodder · Jan 19, 2012 at 12:33 AM · javascriptvector3arrays

Saving Certain Vector3's positions

I am working with editing meshes and I want to sort of stair step my edits. I want them to make very small changes and the vertices that are changed are saved in a new array that will then be changed again until the next step of editing array length is 0 and then it will stop. I have a script that edits but doesn't go past the very first step:

 var firststep : Vector3[];
 
 
 function Start() {
 var mesh : Mesh = GetComponent(MeshFilter).mesh;
 var vertices : Vector3[] = mesh.vertices;
 var normals : Vector3[] = mesh.normals;
    
 for (var i = 0; i < vertices.Length; i++)
 {
 number1 = Random.Range(0,1);
 vertices[i] += normals[i] * number1;
 
 if ( number1 > 0)
 {
 // here is where I want to add the changed vertices
 firststep.Add(vertices[i]);
 }
 
 }
 mesh.vertices = vertices;
 print(firststep.Length);
 }

so far though this always prints the firststep.Length as zero. It's not adding any of the changed vertices when I can clearly see them changing. Any ideas?

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

Answer by Eric5h5 · Jan 19, 2012 at 01:42 AM

You can't add anything to fixed-size arrays like Vector3[]. Use List instead.

Comment
Add comment · Show 11 · 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 cidmodder · Jan 19, 2012 at 02:06 AM 0
Share

I tried array lists and ran into all sorts of trouble. how would I do that? I was using this http://answers.unity3d.com/questions/17033/how-do-you-use-removeat-or-add-with-an-array-of-ga.html but I don't know if I was just doing it wrong or what.

avatar image Eric5h5 · Jan 19, 2012 at 02:14 AM 0
Share

No, List, not array lists. http://msdn.microsoft.com/en-us/library/6sh2ey19.aspx

avatar image cidmodder · Jan 19, 2012 at 02:46 AM 0
Share

so would it be public List firststep for my variable and then just firststep.Add(verticies[i]) ?

avatar image cidmodder · Jan 19, 2012 at 03:07 AM 0
Share

After playing with it I'm getting the error NullReferenceException: Object reference not set to an instance of an object $$anonymous$$eshEditing.Start () (at Assets/$$anonymous$$eshEditing.cs:25)

everytime number1 = 1. can I not just type firststep.Add(vertices[i])? I'm using IList by the way or is that not right?

avatar image Wolfram · Jan 19, 2012 at 11:12 AM 0
Share

List< Vector3>, not List.

Show more comments
avatar image
0

Answer by Wolfram · Jan 19, 2012 at 01:20 AM

There are two versions of Random.Range(x,y), one for integers, and one for floats. You are passing two integers, so it will return an integer between x and y-1, which in your case is always 0. Make sure you pass two float values to that function, in which case it will return a float value within that range.

I don't use UnityScript, so I'm not sure about the syntax, but it should be something like

 number1 = Random.Range(0.0,1.0);
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 cidmodder · Jan 19, 2012 at 02:08 AM 0
Share

You are right I forgot the last number is y-1 haha but it still doesn't add the arrays like i need. Eric5h5 is on the right track I think.

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

6 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Multiple Cars not working 1 Answer

Why does it give me this error and how can i fix it? 1 Answer

Having trouble using a line renderer to show a projectile's predicted trajectory. 1 Answer

What is the problem with this code? 1 Answer

For values in array 2 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