InputField.caretPosition not working on iOS with mobile input hidden

I’ve created a script to allow you to tap on the screen to position the caret within an InputField on iOS by tapping on letters in the field.

The caret positions perfectly before or after the letter by setting InputField.caretPosition, however as soon as you start typing again the caret jumps to the end of the line and the text appends to the line rather than adding in where the caret is.

Any one else found this, or have a work around?

Submitted a bug:
726802

This has been a known issue for a while so i’m closing your bug as a duplicate.

This issue is that the touch screen keyboard has no way of positioning the caret on the device and the device always sets the caret to the end. Its something i’m working on but is something i need to implement on multiple devices which takes time.

Fair enough, thanks for taking the time to look.

I might try and implement a workaround - perhaps store the last caret position at the end of late update and check for changes to the .text value in the field. If it finds any then it resets the caret and puts the text at the last known position? Might be flickery though if the text extends past the end of the box I suppose

If you can find a work around by all means use it as i don’t know when i’ll be able to get this work released.

Is that has been solved?

Yeah not sure if this has been solved yet

Does anyone know if the caret positioning has been fixed or have a working solution? I have an InputField which works fine when playing inside the Editor. However, when I build and deploy to my iOS device, the behavior is not like any other form field I’ve seen in other languages. If you start typing in the field and mobile click somewhere in the typed text area to make a correction, the cursor appears to be located where you clicked until you start typing again, at which point all edits are applied starting at the end of the text line. I’ve tried lots of options like keyboardType, setting caretPosition, etc but nothing seems to work. Does anyone have a workaround or ideas on what I’m doing wrong? I’m using Unity 2018.3 Pro version if that matters. Starting an upgrade to 2019.3.6 to see if problem exists in this version. Thanks for any help or advice.

What version of the TMP package are you using?

Please test with the latest version which is 2.1.0-preview.8 for Unity 2019.x.

Stephan_B, I’m using TMP 1.3.0 - will upgrade and try newer version. Thank you for recommendation. Will reply if this fixes the problem.

Hi Stephan_B, I upgraded from 2018.3 to 2019.3 which include the newer TMP version. Works like a charm on iOS mobile now. Thank you. As is often the case with upgrades though, it didn’t come without a few hurdles to solve. Glad to have it working with 2019. Thanks again!

Has this been fixed for regular InputField?

Same issue with regular Input Fields. Seems TMP is no longer supported in the latest version of Unity 3D 2020.2.

When I have Hide Mobile Input enabled, and press my finger in the middle of text, it jumps caret to the end and opens keyboard.

I press again, the keyboard goes away, press again and keyboard opens and jumps caret to end of input.

Strange thing it works fine on IOS 14.4 and on PC and Mac, however does not work on Android version 11, Ultra S20.

It use to work in older versions of Android and Unity. Now when I press any Input Field, Single Line or Multi Line with Mobile Input disabled, the keyboard opens and jumps Caret to the end instead of where I press within the text.

I am upgrading from Unity 2020.2.1f1 to 20.20.2.7f1 to see if this is resolved and will let you know.

Not sure if this is an Android issue or Unity3d issue.

TMP is still very much supported and on active development. The latest release of the TMP package for Unity 2020.x is version 3.0.4 available via the package manager.

In terms of the keyboard behavior on Android, it is driven by Android native code where we don’t have control over the opening and closing of the input fields. This is something I have asked the Android team at Unity to look into.

You should be able to find several posts on the forum about this. One such post includes reference to a bug report for tracking this issue.

Nope, after updating Android Studio to 4.1.2 and Unity 2020.2.2.7f1, now the app will not open at all on Android version 11. I created a Google Play build, uploaded for internal testing, and not working now. I tried to revert back to Unity 2020.2.1f1 and still not working. Must be something with Android Studio 4.1.2.

I made a backup first, however feel it has something to do with latest version of Android Studio. All the Android packages for Android 10 and above were already updated so they did not require any updates, only Android Studio was updated and Unity 3D.

So now I need to figure out why my app is broken and how to fix. Always updates and things breaking, makes me want to stop developing apps and games, lol :slight_smile:

When I go to Package Manager and TextMesh Pro then view in the Asset Store, it says it is no longer supported.

Unfortunately, TextMesh Pro is no longer available.
This package has been deprecated from the Asset Store. This means that new purchases of the package are not allowed and that only users who already purchased or downloaded the package before it was deprecated, are allowed to download it.
In most cases, package deprecation happens because the publisher is unable or unwilling to support the package anymore. We suggest looking for alternative packages or contacting the publisher directly.
If you’ve already purchased it and need to download a copy, you can do so here.

So I figure it was removed. I did a search for TMP or TextMesh Pro and just see addons and not the actual version.

Well I know this is an Android thing as I’ve seen other articles about this. After updating Android Studio to 4.1.2, nothing is working now, just a quick black screen, green dot in top left corner, and it immediately closes the app.

I am looking into why this is not working.

The version of TextMesh Pro available on the Asset Store is the legacy version which was for Unity 2017 or older. Since Unity 2018.x , TextMesh Pro has been available via the Package Manager as seen below.

6908633--809321--upload_2021-3-6_13-34-5.png

As you can see the latest release is version 3.0.4 which was released on Feb 19.

Since you appear to be using the legacy Asset Store version of TextMesh Pro, you will need to migrate from this Asset Store (dll) based version of TMP to the Package Manager version as a lot of changes have occurred over the past 4 years. See the following post / thread about how to migrate to the Package Manager release of TMP.

In case you did not know, TextMesh Pro was acquired by Unity 4 years ago and it still very much on active development. Since it is now part of Unity, it is available via the Package Manager and no longer via the Asset Store.

It seems the update from 2020.2.1f1 to 2020.2.2.7f1 caused the issue of the app on Android crashing. All it said it the Android Device Monitor Log Cat was this.

The file com.appname/base.apk/assets/bin/Data/level0 is corrupted! Remove it and launch unity again! [Position out of bounds!] Fatal signal 5 (SIGTRAP), code -6 (SI_TKILL) in tid 10004 (Thread -5)

So I attempted to revert back to 2020.2.1f1 and still had the problem. I then restored from a backup I did before upgrading to 2020.2.2.7f1 and this fixed the problem with the app crashing on Android 11.

With Android studio 4.1.2 and all updates, and the app is now back at 2020.2.2.1f1, I am able to build for Google Play, however the input fields still do not work correctly.

Unable to press in the middle of text like you can on IOS. Also I noticed if I type fast, the text gets hosed up, it jumps back a couple spaces. Like typing my password or any text, it starts typing and jumps a character or two behind and caused the password to fail, or messes up typing and you can’t easily go to that spot and fix. Have to delete all text.

I understand this can be an issue with the latest version of Android 11 and Unity running on this version.

Was looking for an easy fix. Works fine in Editor on Windows, Mac, and IOS, just not on Android. I was thinking a function that prevents Keyboard from opening, capture caret position, then enable keyboard, and jump to that position. I tried some code here and there, and haven’t fixed it yet.

The TextMesh Pro says it is no longer available. I can download previous versions however if this is no longer supported, I would hate to run into an issue with having to go back to standard fields and wasting time in future releases.

Will wait for Android 12 to hopefully fix this issue. If anyone has a piece of code that can allow for caret position within text selected, that will be helpful for many.

I will keep messing around with the code. If I figure something out, will post here.

OK, I understand now about TMP, however, does it do the same thing as standard fields on Android? I have the older asset store for TMP.

If it works better on Android with the ability to press in the text, I will consider updating all the fields to TMP, however if it behaves the same way on Android as a standard field, and does not move caret to position selected, then it is not worth the time to switch to TMP.

Have you tested TMP 3 field on Android and does it work as expected, or does it just open keyboard and jump to end of text.

Also the fast typing, this seems to be a known issue as well. While typing fast, it jumps a character or two behind.

I will look at updating TMP and run a test, I just didn’t want to have to do all these code changes for TMP if it does the same thing on Android 11 as a standard field does.

There has been a massive amount of changes in TMP over the past 4 years with the addition of many new features. Besides having to migrate from the legacy version to the newer package manager versions which will require using the Project GUID Remapping Tool, you will most likely run into stuff that will require changes, tweaks, etc.

In terms of the Input Field, I would suggest creating a new project just for testing the TMP Input Field on Android in 2020.x using this latest release of TMP. If it behaves more as you would expect, then consider migrating your main project over.