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 · Apr 09, 2015 at 04:27 AM · javascriptguiinputtextfieldupdating

Text.Field erratically updating

Hi Unity Community!

I am in the process of creating a script which will allow users to adjust the vertices of an object (in this trial case, a simple cube) via the GUI in the script. As I am very new to Unity, I have finally managed to get the vertex vectors into the GUI textFields which is great, however the textFields won't allow user input (by 'won't allow' I mean the fields won't let the user delete values of the vertices and replace them with new ones).

The script isn't throwing any errors but via my rudimentary Debug.Log and research on other existing posts on this topic, I think that the fields are constantly being updated outside of the function. If anyone would be able to cast some light as to the cause of this issue or areas for me to look into I would be very, very grateful!

 #pragma strict
 
 private var menuArea : Rect;
 private var menuAreaHidden : Rect;
 private var mesh : Mesh;
 var vertVect : Vector3[];
 var vertLength : int;
 var vertAdjustField : String;
 
 function Start () 
 {
     menuArea = Rect( 0, 0, Screen.width * 0.1, Screen.height * 0.9 );
     menuAreaHidden = Rect( 0, 0, Screen.width * 0.3, Screen.height * 0.15 );
     VertReport();
     vertAdjustField = String.Empty;
 }
 
 function Update () 
 {
 
 }
 
 function VertReport() 
 {
     var mesh : Mesh = GameObject.Find("Cube").GetComponent.<MeshFilter>().sharedMesh;
     vertVect = mesh.vertices; //original vert positions held in vertVect
     for (var i = 0; i < vertVect.Length; i++) //move through ea. of the vertices until end of array
     { 
         Debug.Log( vertVect[i] );
     }
     mesh.vertices = vertVect; 
     Debug.Log(mesh.vertexCount);
 }
 
 function OnGUI () {
 
     GUI.Box( menuArea, "CubeTest03" );
         GUILayout.BeginArea( Rect( menuArea.x + 10, menuArea.y + 30, menuArea.width - 20, menuArea.height - 50 ) );
             GUILayout.BeginVertical();
             var vertLength = vertVect.Length;
                 for (var i = 0; i < vertVect.Length; i++) //issue is not here (check w/ limit of 8)
                     { 
                         Debug.Log("InputFieldCheck");
                         vertAdjustField = new GUILayout.TextField( "v" + vertVect[i], 25 );
                     }
             GUILayout.EndVertical();
     GUILayout.EndArea();
 }


Many thanks in advance,

Ryan

Comment
Add comment · Show 3
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 RyanAchtenSoma · Apr 08, 2015 at 11:50 PM 0
Share

I forgot to mention; I'm uncertain if the vertVect.Length is returning the actual length of the array as this seems to go on forever - I'm not sure if this is a related factor or not. However I have tested around this using other < limits to no avail so I'm pretty sure it is not the cause of the issue.

avatar image NoseKills · Apr 09, 2015 at 04:03 PM 1
Share

If I understood right... The problem is that you draw textfields with vertex positions in the gui, but you don't do anything significant with the values the user types in.

  vertAdjustField = new GUILayout.TextField( "v" + vertVect[i], 25 );

Whatever the user types in, you assign into vertAdjustField. You don't do anything with what the user types in and in the next OnGUI call you just draw the contents of vertVect[i] again.

You have to parse vertAdjustField to see what the user tried to set into the vertex, and eventually place it back into vertVect and the mesh.

Also a cube has 6 sides, each side has 2 triangles, each triangle has 3 vectors so there are supposed to be 36 vectors in the list

avatar image RyanAchtenSoma · Apr 13, 2015 at 07:35 AM 0
Share

Hi @Nose$$anonymous$$ills

Thanks for your prompt response! I have spent the last few days trying to rectify my code inline with your suggestion, however to no avail.

I have tried storing the string result of the textField to another variable to assign back into the textField (I have annotated my logic in the attached code) but can't get anything to work. I'm struggling to find useful tutorials in .js on the topic so would you please expand on where my logic is missing.

$$anonymous$$any thanks in advance! Ryan

 #pragma strict
 
 private var menuArea : Rect;
 private var menuAreaHidden : Rect;
 private var mesh : $$anonymous$$esh;
 var vertVect : Vector3[];
 var vertLength : int;
 var vertField : String;
 var vertFieldResult : String;
 //var vertTextField : TextField;
 
 function Start () 
 {
     menuArea = Rect( 0, 0, Screen.width * 0.1, Screen.height * 0.9 );
     menuAreaHidden = Rect( 0, 0, Screen.width * 0.3, Screen.height * 0.15 );
     VertReport();
     vertField = String.Empty;
 }
 
 function Update () 
 {
 
 }
 
 function VertReport() 
 {
     var mesh : $$anonymous$$esh = GameObject.Find("Cube").GetComponent.<$$anonymous$$eshFilter>().shared$$anonymous$$esh;
     vertVect = mesh.vertices; //original vert positions held in vertVect
     for (var i = 0; i < vertVect.Length; i++) //move through ea. of the vertices until end of array
     { 
         Debug.Log( vertVect[i] );
     }
     mesh.vertices = vertVect; 
     Debug.Log(mesh.vertexCount);
 }
 
 function OnGUI () {
 
     GUI.Box( menuArea, "CubeTest03" );
         GUILayout.BeginArea( Rect( menuArea.x + 10, menuArea.y + 30, menuArea.width - 20, menuArea.height - 50 ) );
             GUILayout.BeginVertical();
             var vertLength = vertVect.Length;
                 for (var i = 0; i < vertVect.Length; i++) //for every vertex in mesh
                     { 
                         vertField = "v " + vertVect[i];//vertField is assigned vertex vectors from mesh
                         var vertTextField = new GUILayout.TextField( vertField, 25 );//textField crated for each vector set 
                     }
                 var vertFieldResult = vertTextField; //vertFieldResult holds the user input return of this textField
                 vertTextField = GUILayout.TextField( vertFieldResult, 25); //vertTextField is assigned user input
             GUILayout.EndVertical();
     GUILayout.EndArea();
 }
 


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

3 People are following this question.

avatar image avatar image avatar image

Related Questions

Input not registering while TextField is selected 3 Answers

Need help using GUI.Button/ input storage 1 Answer

TextField, Event.current, Input.GetKey, and GUI.FocusControl locking 1 Answer

Backspace in limited length textfield causes ArgumentOutOfRangeException 1 Answer

Android Textfield locks out input until esc 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