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 RyanAchtenSoma · May 06, 2015 at 11:45 PM · arraystringinputfieldtriangles

Assigning Triangles from String Array issue

Hi Unity Community

Probably a pretty simple issue. I am trying to parse the string values from an input field to define a mesh, and while I have the UV and vertex variations working fine, I can't see to complete the functionality for assigning triangles.

The current issue here is the script is throwing me a 'Array index is out of range' error, and no matter what I change in the array assigning process I can’t seem to resolve this. Not only does it not work but it also causes an issue with accessing the Mesh Filter of the game object the user input is meant to updating and disables the other toggles’ functionality from working. I’m quite new to the splitting of strings so I’m sure this is a simple mistake; any guidance would be very much appreciated!

Here is my code:

 function ExpVertText(userText : String) // for importing verts back to Mesh from input field
 { 
     
     var textArray = userText.Substring (1, userText.Length-2).Split ([")("], System.StringSplitOptions.RemoveEmptyEntries);
     var curObj = GameObject.Find("TestObject"); //current object
     var curMesh = curObj.GetComponent(MeshFilter).mesh;
     
     //**Vertice Import**
     var vertToggle = GameObject.Find("VertToggle").GetComponent(Toggle);
     var curVertArray : Vector3[] = curObj.GetComponent(MeshFilter).mesh.vertices; //current verts
     var vectArray = new Vector3[textArray.Length];//new verts
     
     //**UV Import**
     var uvToggle = GameObject.Find("UVToggle").GetComponent(Toggle);
     var curUVArray : Vector2[] = curObj.GetComponent(MeshFilter).mesh.uv; //current UV's
     var uvArray = new Vector2[textArray.Length];//new UV's
     
     //**Tri Import**
     var triToggle = GameObject.Find("TriToggle").GetComponent(Toggle);
     var curTriArray : int[] = curObj.GetComponent(MeshFilter).mesh.triangles; //current Tri's
     var triArray = new int[textArray.Length];//new Tri's
     var triTextArray : String[]; // holds string tri vals from text input
     var triTextInts : int[]; //holds Tri int values    
             
                     
     //**Issue Section** Tri Update
     triTextArray = userText.Split(""[0]); //string to string array for ea. value
     for (var m = 0; m < triTextArray.Length; m++) { 
         
         if (triToggle.isOn)
             {
                 triTextInts[m] = parseInt(triTextArray[m]); // string array parsed to int array
                 Debug.Log( "Stored triTextArray: " + triTextInts[m]);
                 
                 Debug.Log("Old Tri: " + curTriArray[m]);
                 curTriArray[m] = triTextInts[m];
                 Debug.Log("New Tri: " + curTriArray[m]);
             
                 curObj.GetComponent(MeshFilter).mesh.triangles = curTriArray;
                 Debug.Log("New Tri - Mesh Updated");
             }
     }
     //***Store Values***
     for (var i = 0; i < textArray.Length; i++) { 
         var numbers = textArray[i].Split(","[0]);
         if (vertToggle.isOn)
             {
             vectArray[i] = Vector3(parseFloat(numbers[0]), parseFloat(numbers[1]), parseFloat(numbers[2]));
             }
         if (uvToggle.isOn)
             {
             uvArray[i] = Vector2(parseFloat(numbers[0]), parseFloat(numbers[1]));
             }
         }
     //***Vert Assign***
     if (vertToggle.isOn)
         {
             for (var j = 0; j < vectArray.Length; j++) 
             {
                 Debug.Log("Old vert: " + curVertArray[j]);
                 curVertArray[j] = vectArray[j];
                 Debug.Log("New vert: " + curVertArray[j]);
             
                 curObj.GetComponent(MeshFilter).mesh.vertices = curVertArray;
                 Debug.Log("New Verts - Mesh Updated");
             }
         }
     //***UV Assign***
     if (uvToggle.isOn)
         {
             for (var k = 0; k < uvArray.Length; k++) 
             {
                 Debug.Log("Old UV: " + curUVArray[k]);
                 curUVArray[k] = uvArray[k];
                 Debug.Log("New UV: " + curUVArray[k]);
             
                 curObj.GetComponent(MeshFilter).mesh.uv = curUVArray;
                 Debug.Log("New UV's - Mesh Updated");
             }
         }
     return curObj;
 }


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

0 Replies

· Add your reply
  • Sort: 

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

19 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

Related Questions

how can i split a word to individual letters..?? 2 Answers

Array Slit String and Send NGUI text 0 Answers

Newbie Problem with Multidimensional Arrays in JavaScript 0 Answers

Iterating through multidimensional arrays 2 Answers

Comparing a string to an array extraction? 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