Is it possible to change the caret style inside TextField? For example, making it wider and a bit more visible etc.
Using UI Toolkit Preview 12
Is it possible to change the caret style inside TextField? For example, making it wider and a bit more visible etc.
Using UI Toolkit Preview 12
Hi @herra_lehtiniemi !
It’s not something we currently support, but I’ll make sure we keep track of this because it would indeed be a really neat feature.
Yea! In my case, for example, I have a white background and black font color. The caret is really invisible and not blinking, so it’s hard to find it. Having it blink and a bit wider and in black would really help locating it quickly in a very big multiline TextField.
Would be easiest to be able to style it directly via USS, maybe some -unity-caret-type with blink/no-blink, -unity-caret-blink-speed or something in that general direction.
Hello, I also would like to see this feature. Specifically being able to change the caret color so we can make a dark textbox:
I wanted to add that I am having the same challenge. A big UI challenge that I have not been able to come up with a solution so far. Really need a built in feature to solve for this.
We are planning to improve the InputFields for 2023.1 and improving the customizability of the caret and selection will be part of it.
Thank you for the prompt reply @HugoBD-Unity ! Any chance this change can be pushed to something in 2022 or anything earlier than 2 years from now?
Could really improve adoptability of the UI for mobile apps and we could really use it!
A workaround suggestion would be very helpful too. If you can think of anything we can do.
Thank you!
We also have a project with a black background. And you can guess where the caret is
You might be able to set the cursor color through USS using this custom style:
--unity-cursor-color:#B4B4B4;
Let me know if it worked!
The custom style worked in 2021.2.9
thx
Another thing: can we make it blink?
It is so static…
Hi @manuelgoellnitz !
We are aware that InputFields are lacking a blinking cursor, and it’s something we are looking to add.
In the meantime, you could do something like this to add a blinking cursor:
C#:
public static void BlinkingCursor(TextField tf)
{
tf.schedule.Execute(() =>
{
if(tf.ClassListContains("transparentCursor"))
tf.RemoveFromClassList("transparentCursor");
else
tf.AddToClassList("transparentCursor");
}).Every(1000);
}
USS:
.transparentCursor {
--unity-cursor-color: rgba(0, 0, 0, 0);
}
I didn’t think of that although it’s quite obvious
I made it a bit more efficient and let it only run, when the textfield is in focus.
Thanks for the workaround! However it would be really nice to have this behaviour by default
I discoverd that when the UI is “Scaled with Screen Size” also is the caret. And since this is allways done to a full pixel, the caret is scaled to 0px width in my case. Which is not very usefull.
Is there a way to resize it?
Hi @manuelgoellnitz !
Thanks for bringing this up, it’s an issue that has already been reported. We’ll look into it shortly and this will be backported. There’s a property to change the cursorWidth, but it’s currently internal. We are also looking to expose it.
Hi,
Any ETA on this one @HugoBD-Unity ?
Hi @pawelduda ! We still plan to provide a blinking-cursor and to expose the cursorWidth but it’s currently not in the work. No clear ETA on these tasks yet.
As for the cursor being 0px depending on scale, this is a high-priority bug for us and we’ll look into this one shortly.
Hi,
I was using this solution but after upgrading to Unity 2022.2.5 it doesn’t seem to work anymore. Did something change to the API?
@ChGuidi from which version did you upgrade from?
The inner hierarchy of the TextField changed in 2022.1, you might need to retarget the USS selector. For more info on the refactor have a look at this forum post .
Thanks for the quick reply. We upgraded from 2022.1.24 and there it was still working. I was trying a couple of things to change the cursorColor in code instead of from uss but it’s not doing much. To where should I retarget the USS selector?