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
1
Question by zoran404 · Jan 21, 2015 at 11:46 AM · c#guitext

Text object can't be edited

I have an input field and event that calls a function when I press enter.

 public Text theText;

I take the Text part of the input field (connect them in editor), display the content and set new value to some string.

 Debug.Log(theText.text);
 theText.text = "new text";

I get the contents displayed, but the value isn't changed.

Why am I able to read but not write to it? And how do I fix this?

EDIT: To clarify, I'm talking about the new ui system. I tried creating a new scene, with just that input filed with a script (attached to it) that contains the 2 lines I posted earlier (I connect the text field, child of the input field, to "public Text theText;" in editor). And it's not changing text, just showing it. I suppose I could create a GUI.TextField in OnGUI(), that way I could surely change the text value. But the current way I'm trying now worked fine few days ago, I don't get what could not be happening..

Comment
Add comment · Show 5
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 sniper43 · Jan 21, 2015 at 01:50 PM 0
Share

Are you asking why the name of the GameObject hasn't changed?

http://docs.unity3d.com/ScriptReference/UI.Text.html

shows that Text.text is the variable string for what is displayed, it doesn't influence anything else.

Do not modify the name of the actual object itself as that is something even advanced programmers use with extreme caution and I doubt you can find a dozen of them that actually do.

avatar image zoran404 · Jan 21, 2015 at 03:46 PM 0
Share

@sniper43 this has nothing to do with the object name, it's about the text that is displayed in the input field

avatar image Chris333 · Jan 21, 2015 at 08:13 PM 0
Share

Are you missing the EventSystem in the scene?

avatar image sniper43 · Jan 22, 2015 at 12:41 AM 0
Share

@zoran404 There is no input field here and I might just be getting more confused.

Text is a simple GameObject that displays text, it shouldn't take input.

Are you using something like this? (Don't trust me on this, haven't had to use an input field yet) http://docs.unity3d.com/ScriptReference/GUI.TextField.html

avatar image celrackov · Oct 04, 2019 at 11:10 AM 0
Share

I have the same problem :(

3 Replies

· Add your reply
  • Sort: 
avatar image
3
Best Answer

Answer by zoran404 · Jan 23, 2015 at 07:03 AM

For those who are interested the problem was that I tried to directly edit the UI.Text object, which was a child of an UI.InputField object.
When I replaced public Text theText; with public InputField theText; , connected the actual InputField to that variable, not it's child the Text object, tried to change it with theText.text = "new text"; it worked fine.

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
0

Answer by Mmmpies · Jan 21, 2015 at 08:52 PM

Your code looks OK so if this doesn't work then try posting more of the script so we can see what's going on, that said...

public variables are overridden in the inspector, try setting it to private, call the Text object something unique and using GameObject.Find to find it e.g.

 private Text theText;
 
 
 //in start
 theText = GameObject.Find("uniqueTextName").GetComponent<Text>();


example in C#

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
avatar image
0

Answer by AscendDev · Sep 16, 2017 at 12:26 PM

Just as a note, I had the same problem and found that for some reason my input field was under the canvas and not the panel. Dragging it under the panel resolved the issue.

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

8 People are following this question.

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

Related Questions

C# GUI Button 2 Answers

In-game text editor, native or NGUI 2 Answers

v4.6 Create GUI Elements Via Script? 1 Answer

Help with making a triggered gui message 1 Answer

Copy TextField to Clipboard via Button 0 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