I have a game in unity where I instantiate a TouchScreenKeyboard:
keyboard = TouchScreenKeyboard.Open(
"", //text
TouchScreenKeyboardType.Default, //type
false, //autocorrect
true //multiline
);
Later, in Update()
, I run the following:
keyboard.active = false;
Debug.Log("Turned off keyboard. Now: " + keyboard.active.ToString());
However, in my debugger (running on an iPhone through xcode), I only see:
Turned off keyboard. Now: True
Where it gets really weird: the app does correctly start with the keyboard off on the screen, but if I log keyboard.active
it says "True".
When I start the game, the keyboard pops up. However, it doesn't disappear after the game session (where I run keyboard.active = false;
again).
If I unfocus the app at this time, however, the keyboard disappears and when I log the status as Debug.Log(keyboard.active.ToString());
it shows false.
What gives? Is this a weird OS interaction? Should I just figure out a way to spoof unfocusing the app, or is there a trick I am missing to make this work? In the example code they use this exact line of code: https://docs.unity3d.com/ScriptReference/TouchScreenKeyboard-active.html
This is unity 2020.2.0f1