Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 /
  • Help Room /
avatar image
0
Question by DrTanK · Jan 05, 2017 at 10:12 AM · c#uikeyboardwindows 10

InputField remove one character

Hi

I'm working on multitouch apps. These apps are running one multitouch device under Windows 10 I don't have any physical keyboard one these device so i need a virtual keyboard.

I tried this solution : http://answers.unity3d.com/answers/1134812/view.html But the keyboard is really slow and give options to leave my application.

So i start to create my own keyboard. So i create a UIPanel, and buttons for letters This is working well Then i tried to add a backspace button and here start my problem :

I can't erase a character from the input field when i press my backspace touch i call a function where i do this :

 field.GetComponentInChildren<InputField>().text.Remove(field.GetComponentInChildren<InputField>().text.Length, 1);


field is my inputfield gameObject But i have this error :

ArgumentOutOfRangeException: startIndex + count > this.length Parameter name: count System.String.Remove (Int32 startIndex, Int32 count) (at /Users/builduser/buildslave/mono/build/mcs/class/corlib/System/String.cs:1747) Keyboard.addInput () (at Assets/Scripts/Keyboard.cs:23) UnityEngine.Events.InvokableCall.Invoke (System.Object[] args) (at C:/buildslave/unity/build/Runtime/Export/UnityEvent.cs:153) UnityEngine.Events.InvokableCallList.Invoke (System.Object[] parameters) (at C:/buildslave/unity/build/Runtime/Export/UnityEvent.cs:630) UnityEngine.Events.UnityEventBase.Invoke (System.Object[] parameters) (at C:/buildslave/unity/build/Runtime/Export/UnityEvent.cs:765) UnityEngine.Events.UnityEvent.Invoke () (at C:/buildslave/unity/build/Runtime/Export/UnityEvent_0.cs:53) UnityEngine.UI.Button.Press () (at C:/buildslave/unity/build/Extensions/guisystem/UnityEngine.UI/UI/Core/Button.cs:35) UnityEngine.UI.Button.OnPointerClick (UnityEngine.EventSystems.PointerEventData eventData) (at C:/buildslave/unity/build/Extensions/guisystem/UnityEngine.UI/UI/Core/Button.cs:44) UnityEngine.EventSystems.ExecuteEvents.Execute (IPointerClickHandler handler, UnityEngine.EventSystems.BaseEventData eventData) (at C:/buildslave/unity/build/Extensions/guisystem/UnityEngine.UI/EventSystem/ExecuteEvents.cs:52) UnityEngine.EventSystems.ExecuteEvents.Execute[IPointerClickHandler] (UnityEngine.GameObject target, UnityEngine.EventSystems.BaseEventData eventData, UnityEngine.EventSystems.EventFunction`1 functor) (at C:/buildslave/unity/build/Extensions/guisystem/UnityEngine.UI/EventSystem/ExecuteEvents.cs:269) UnityEngine.EventSystems.ExecuteEvents:Execute(GameObject, BaseEventData, EventFunction`1) TouchScript.Behaviors.TouchScriptInputModule:endPointer(PointerEventData) (at Assets/TouchScript/Scripts/Behaviors/TouchScriptInputModule.cs:343) TouchScript.Behaviors.TouchScriptInputModule:processEnded(TouchPoint) (at Assets/TouchScript/Scripts/Behaviors/TouchScriptInputModule.cs:463) TouchScript.Behaviors.TouchScriptInputModule:touchesEndedHandler(Object, TouchEventArgs) (at Assets/TouchScript/Scripts/Behaviors/TouchScriptInputModule.cs:579) TouchScript.Utils.EventHandlerExtensions:InvokeHandleExceptions(EventHandler`1, Object, TouchEventArgs) (at Assets/TouchScript/Scripts/Utils/EventHandlerExtensions.cs:28) TouchScript.TouchManagerInstance:updateEnded(List`1) (at Assets/TouchScript/Scripts/TouchManagerInstance.cs:699) TouchScript.TouchManagerInstance:updateTouches() (at Assets/TouchScript/Scripts/TouchManagerInstance.cs:787) TouchScript.TouchManagerInstance:Update() (at Assets/TouchScript/Scripts/TouchManagerInstance.cs:541)

Then i tried to use a temp string where i remove one character but the string in my inputfield does not change.

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

Answer by KoenigX3 · Jan 05, 2017 at 03:04 PM

The first argument of string.Remove() is the start index. In this situation, the start index equals to the length of the text, which is incorrect. For example, if you have a string of 15 characters, the last character will have an index of '14', that's why you can not remove the character with the index of '15' (since there is no such character).

The solution is to subtract 1 from the start index:

 field.GetComponentInChildren<InputField>().text.Remove(field.GetComponentInChildren<InputField>().text.Length - 1, 1);

This line only creates a new string with the removed character. You have to assign this to the text variable of the InputField (sorry for not mentioning this, my mistake).

 field.GetComponentInChildren<InputField>().text = field.GetComponentInChildren<InputField>().text.Remove(field.GetComponentInChildren<InputField>().text.Length - 1, 1);
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 DrTanK · Jan 05, 2017 at 03:09 PM 0
Share

So yes i tried this and I haven't the error anymore but it remove nothing...

avatar image
0

Answer by DrTanK · Jan 05, 2017 at 04:14 PM

Ok solved the problem by using a temp var But it is strange that i cannot remove the character directly in the inputfield no ? there should be a way to do that without this temp var.... Thx @KoenigX3

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

300 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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

Handling Multiple U.I. Input Fields 0 Answers

Certain scripts that are attached does not work after build, scene change and closing unity 0 Answers

How to add more UI elements to Dropdown OptionData except default string and sprite values in Unity? 0 Answers

Simple Camera Switch Using C# 3 Answers

Display list as UI or GUI 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