Virtual Keyboard not opening in Unity3D with Steam/MRTK - unity3d

I'm developing with Unity using the MRTK (if that matters) and my project setup is using "PC,Mac &Linux Stand Alone", my player settings are set to enable VR.
I'm copying and pasting directly the code from Unity to open the keyboard, and that function is the first one I call when opening the scene, and yet I can't see it. Is there anything wrong/buggy with it?
I even tried it on a completely empty project. Nothing happens.
Directly from Microsoft:
public TouchScreenKeyboard keyboard;
private void Start()
{
OpenSystemKeyboard();
}
public void OpenSystemKeyboard()
{
keyboard = TouchScreenKeyboard.Open("", TouchScreenKeyboardType.Default, false, false, false, false);
}
No error message, no console message, just nothing....

The API in question I believe is only documented to work for the following platforms:
iOS
Android
Windows Store Apps (AKA UWP apps AKA Universal Windows Platform apps)
Since the build process is uses PC/Mac/Linux, it's not a WSA/UWP app, so I wouldn't expect that to show up given Unity's documentation here:
https://docs.unity3d.com/ScriptReference/TouchScreenKeyboard.html
The older version of the MRTK (HTK) had a keyboard prefab that could be used, though note that that branch is fairly old at this point:
https://github.com/microsoft/MixedRealityToolkit-Unity/blob/htk_release/Assets/HoloToolkit/UX/Prefabs/Keyboard.prefab

Related

How do I prevent my app from running in the "recent menu" on Android 12

Android 12 introduced the behavior where the last app you had active are continuing to run when inside the recent menu. I'm wondering if there's a flag or something to put in AndroidManifest file to prevent this behavior as it's conflicting with some logics in our app (which works fine for Android < 12). I've googled but it's hard to find unless you know exactly what this "feature" is called.
Steps:
Start app
Open recent menu
Observe that you can interact and that the app is still running as if you had it open/active
Why is this a problem? Because a user is now able to force quit the app (swiping it away) without entering the "paused" state in our game (using Unity) meaning some save logic won't run.
This can be worked around in one way or another, but for now I would like to just pause the app in recent menu if possible (our app has zero reason for being active in recent menu).
EDIT:
As #WyattL mentioned in his answer, android:excludeFromRecents="true" might work, but it will cause drop in playtime and retention of the game and would prefer to have a more proper solution to this "unnecessary" feature of Android 12.
I can't be sure without testing on every phone as it seems the issue varies by device (thanks Ruzihm), but if opening the Recent Apps screen generates an OnApplicationFocus() call, this would provide a solution.
In an active MonoBehaviour:
private void OnApplicationFocus( bool focus )
{
if( focus ) {
UnpauseLogic();
}
else {
PauseLogic();
SaveLogic();
}
}
(It might also be worth trying OnApplicationQuit() in case it's called on specific devices during a swipe termination, but in my own tests it was never called.)
According to some brief research, did you try adding
<activity>
...
android:excludeFromRecents="true"
android:label=""
...
</activity>
to the AndroidManifest.xml?

Why the IRtcEngine instance is not created?

i'm trying to implement a voice chat in my Unity game using agora.io. I followed the official start up tutorials and I put the code below in a script attached to an empty Gameobject in the scene:
My simple start up script
So, at the Start, the IRtcEngine instance should be created as I call the IRtcEngine.GetEngine(agoraAppID) method. The problem is that, instead od returnig the instance, this method prints an error log: "Create engine failed, error code: -7"
I looked up what the error code 7 means: "A method is called before the initialization of RtcEngine. Ensure that the RtcEngineinstance is created and initialized before calling the method".
So I tried commenting everything but the line in which the IRtcEngine.GetEngine(agoraAppID) method is called, but the error still pops up. It pops up even when I play the agora demo scene "HelloUnity".
I also tried removing the agora package and importing it again. It worked because after that the instance was created correctly, but after a few times, the error started popping up again.
Unity version: 2020.3.3f1
Agora version: 3.3.1.71
What could the problem be? Is it a bug?
I had the same issue with the same error code. Closing all Unity instances and rebooting my computer was helped me.
Usually, it happens if you don't leave the channel properly. So, putting
rtcEngine?.LeaveChannel()
to
OnDestroy()
may be a good solution.
should look something like this. don't forget the variable declaration up top.
public class Launch : MonoBehaviour
{
public IRtcEngine mRtcEngine;
void Start()
{
string agoraAccountId = "4ca78bc86f23hhhhhhhhh4444444444";
if (mRtcEngine != null)
{
Debug.Log("Agora engine exists already!!");
return;
}
mRtcEngine = IRtcEngine.GetEngine(agoraAccountId);
I suggest you join the Agora slack channel (it is easy to join) where you can get answers quickly.
Please take a look at the Demo project code and watch out how the sample app handles the life cycle in Unity. In your simple script, there is no clean up code on destroy. You left certain socket/ports open on the system. That's why when you get some success on a fresh install but not the subsequent run.

Unity WebGL Mobile browser workaround and keyboard input fix?

Hey everyone so I read that unity doesn't really support mobile browsers for WebGL games. im using 2020.1.4.And sure enough, the game gets a bit distorted by not being scaled properly. it's like the camera is bigger so it shows on the screen that blue color. I tried some things, setting width and height to auto or removing config.devicePixelRatio = 1; as suggested by a friend but nope! still looks horrible! And if that wasn't enough the keyboard doesn't show up when clicking on form fields. i tried this one
https://github.com/eforerog/keyboardMobileWebGLUnity
which displayed an error when pressed on and this one
https://github.com/dantasulisses/WebMobileInputFix which just didn't even compile!
Any ideas, please?
I did my research and tried every plugin I could find. I used Unity 2020.3.28f1 and tested both on Android-phone and iPhone.Here is my report.
These plugins don't work:
https://unitylist.com/p/f58/Unity-webgl-inputfield
https://github.com/eforerog/keyboardMobileWebGLUnity
https://github.com/dantasulisses/WebMobileInputFix
This plugin works, but you should use different settings for IOS and Android on same input field game object. If you use "prompt", it works for IOS only, and "overlay" works for Android only. Look for documentation in page:
https://github.com/unity3d-jp/WebGLNativeInputField
And this plugin works best at the moment. Yes, it is a bit ugly though, but it works.
https://github.com/kou-yeung/WebGLInput
And there is a fix for Unity 2021 for it:
https://github.com/kou-yeung/WebGLInput/releases/tag/1.0
There's a keyboard that overlays, when using it you just need to tap the notification to access it and then click the "back" button to hide it https://play.google.com/store/apps/details?id=com.fishstix.gameboard
I made this project that simply recreates a keyboard using buttons in unity.
I implemented it in a WebGL build successfully.
https://github.com/thetimeste/WebGL-Build-Keyboard-Unity.git
I would recommend using the native js window.prompt() fields as of writing. They have great cross-platform support, allow for extra features like special characters, emojis, copy and paste etc. and are pretty easy to set up. Once (or honestly if ever) Unity adds their own reliable implementation you can easily remove this lightweight implementation.
Create a .jslib file that has a function opening a window.prompt(description, currentText)
Return the result at the end of that function back to a unity object with a recipient script
Make a derivation from Unity's event system overwriting the OnApplicationFocus(bool focus) function (leaving it empty), to fix a sneaky Chrome Android bug.
That's it. The result should look something like in this demo: https://pop.demo.neoludic.games
If you want to save some development time on a feature that really should just be native in Unity, you can also check out my plugin based on the method above. https://neoludic-games.itch.io/pop-input
I also need to enable mobile virtual keyboard for running webgl on mobile device.
I've tried the code from your mentioned url. It gives you some idea on how to do
it, but the code are totally buggy and unusable. Now I am trying to implement it
by myself.

Memory Access Out of Bounds - WebGL

I was getting this error when I try to load my Web game:
My game is loaded at this domain:
Highest Flavor Website Link
This is my project settings at the time of build export:
Please give me some suggestion to solve this problem.
This error happened to me due to using the dynamic keyword. After replacing all my dynamic types with object the error was gone. Apparently the dynamic keyword is not supported on WebGL builds.
I've finally fixed the same error in my project. Here is what i did:
Narrow down the line of code that crashes WebGL.
Go through the painfull process of pinpointing the line of code that
is the source of the error. I had this "luck" that error occured
when I've hit button and tried to load UIScene in Addition mode. So
at first I found the script in the scene which when disabled got rid
of the crash. Then I've repeated the steps and digged deeper into
lines. After 2 hours of builds, comments etc I've found that the code
was not working was setting the new color for UnityEngine.UI.Image.
Which was pretty weird because in playmode everything worked ok.
Find solution. I think my solution might not be universal but I think there is something going in the Unity gameloop/lifecycle when running WebGL. The source of the problem was that i set the field that was storing my UI.Image in the Start method and then in some function I've tried to change the color.
Property was not exposed in inspector.
public class ModuleUI : MonoBehaviour
{
Image qualityBG;
void Start()
{
qualityBG = GetComponent<Image>();
}
...
then this line below was the cause of the crash
public void Set(Module module)
{
...
qualityBG.color = module.Quality.ToColor();
}
Fixing - so I've added [SerializeField] attribute to the field and set it up in editor, dragged the Image into the inspector slot. An it fixed it. I suspect that WebGL build might perform some methods in different order, or maybe the multipleScene loaded together might to do with it. I'm not sure but the field was not set properly with previous code fot WebGL build.
Bonus:
I've also fixed some issues that was not critical (not crushing WebGL game) but not working properly as expected in playmode. This also has got to do with trying to set some object in Start() method and then doing something on them. The collection was not set up (probably null) in WebGL.
EffectUI[] effects;
Start()
{
effects = GetComponentsInChildren<EffectUI>();
}
void HideAllEffects()
{
if (effects != null)
for (int i = 0; i < effects.Length; ++i)
effects[i].gameObject.SetActive(false);
}
And this also started working when I've added [SerializeField] to effects and hook it up in the scene...
Hope this will help some of you guys & gals!
To run this build within the web browser - I have removed all extra things related code those can't work within the web build like in-app purchase, advertisements, leaderboard, native sharing etc...
After these things code removed from the project, I uploaded the exported build content to my hosting. Then after it started working properly.

Close Unity Inside Android App

Actually I have an Android App in which I run my Unity3D game. Everything works well together. Now, when I launch Unity inside my app the game starts normally but if I try to go back to my AndroidApp intent I received a "SIGNAL 11 SIGSEGV" and Unity just close.
This happens when I'm drawing a Menu inside Unity and press "Exit" button to close Unity but if I do the same with the Android back buton Unity closes normally without problems.
I'm using plugins in Unity to achieve this behaviour.
My Function in Unity Side :
public void ExitGame()
{
#if UNITY_ANDROID
AndroidJavaClass unityPlayer = new AndroidJavaClass ("com.unity3d.player.UnityPlayer");
AndroidJavaObject activity = unityPlayer.GetStatic<AndroidJavaObject> ("currentActivity");
activity.Call ("ReturnToMainActivity", "Hello");
#endif
}
Function in Android Side :
public void ReturnToMainActivity (String someText)
{
Log.v("Unity", "Finish Unity from Android" );
this.mUnityPlayer.quit();
UnityPlayer.currentActivity.finish();
}
Again, this works normally if I press the Android Back Button inside Unity app but when I try to do the same with an Unity GUI.Button I received a "SIGNAL 11 SIGSEGV". In Both Cases logcat print the message "Finish Unity from Android" so I think Unity calls the function normally but in some Point just crashes.
Someone post faced the same problem but I can't figure out how he solve it.
SIGNAL 11 SIGSEGV crash Android
Ok, I just figure out how to do this.
In my function inside Android Side:
public void ReturnToMainActivity (String someText)
{
UnityPlayer.currentActivity.runOnUiThread(new Runnable(){
public void run()
{
Log.v("Unity", "Aplicacion de Unity terminada desde Android" );
ElJuegoActivity.this.mUnityPlayer.quit();
UnityPlayer.currentActivity.finish();
}
});
}
And that does the trick. No issues or problems.
NOTE: This is the "answer" the OP originally included at the end of his question. I've separated it into its own CW answer. If the OP returns and wants to post it himself, by all means ping me