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 harveyhb · Oct 17, 2014 at 05:59 PM · uiguiinputfield

How to pass string from input field using "OnSubmit (String)"

I'm using the new GUI system in the 4.6 Beta.

I've added a InputField UI element. I want to pass the string that is typed in the input field to the function I have created below. I've dragged the Gameobject containing the component with said function onto the On Submit (String) event, selected the public function below. The string isn't getting passed, also , the function isn't even being called.

Any Ideas?

     public void SetClientAppName (string name){
         Debug.Log("Called :  " + name );
         clientAppName = name;
         RestartSyphon ();
     }
Comment
Add comment · Show 1
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 harveyhb · Oct 17, 2014 at 04:41 PM 0
Share

I've also tried to just calling this...

      public void SetClientAppName (){
          Debug.Log("SetClientAppName Called" );
      }

Without the string parameter, and it's still not getting called when text is entered.

3 Replies

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

Answer by harveyhb · Oct 17, 2014 at 07:16 PM

For anyone having this problem in the future.

On the InputField component, there is a checkbox for "Multi Line". Every time I pressed enter to submit text I was of course just starting a new line.

What this didn't solve is how to pass the string entered in the checkbox to my SetClientAppName function. I still haven't found a way to do this using OnSubmit (string) as this just passes whatever string is entered into the textbox to the right of the drop down to choose the function.

Instead I created a public input field and listener like so. Remember to include the "using UnityEngine.UI" header.

 public InputField newClientName;
 
 void Awake (){
     newClientName.onSubmit.AddListener((value) => SetClientAppName(value));
     }
 
 public void SetClientAppName (string name){
     Debug.Log("Called :  " + name );
     clientAppName = name;
     RestartSyphon ();
     }

 
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 Zagule · Sep 09, 2019 at 10:57 PM 0
Share

Thanks for the code! I was browsing so many useless threads and video tutorials and none showed how to simply send the value, like you did in your Awake().

avatar image
3

Answer by sollersstudios · Apr 23, 2015 at 01:33 PM

You can have the parameter of the function be a UI.Text component, and then add the reference of the same Text object as the value of the parameter your passing in.

 public void UpdatedTextBox(UnityEngine.UI.Text newValue)
 {
         Debug.Log("Text was updated to: " + newValue.text);
 }
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
2

Answer by jhocking · Nov 02, 2014 at 07:51 AM

As you already noticed, hitting Enter just creates a newline when the text is set to Multiline; according to threads on the forum, in the next version they added a selection for how to handle Enter.

As for the text being submitted, make sure to select function in top section "Dynamic string" and not bottom section "Static Parameters". I had the same issue at first and it took me a while to figure out; apparently you can use either dynamic or static string parameters and I had selected the function in static.

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

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

Terminal-like GUI, wait for input 1 Answer

Scaling image width in script error 0 Answers

Monopolize keyboard for InputField (uGUI) the same way it works for TextField (IMGUI) 0 Answers

Prevent to Deselect InputField 0 Answers

Caret appearing at the beginning of input fields on iOS. 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