-> Summary:
I want to send messages from AndroidStudio - Code to Unity - Normal way doesn't seem to be working.
-> What I tried:
I have two projects in Unity3D. They are exactly the same, except that one of them is set up for the Oculus Gear Vr... Then I export (Android) both of these Projects and open them as AndroidStudio Projects. When i run these now both work exactly as expected !
But when i try to use the UnityPlayer.UnitySendMessage - method, the method seems not to be executed in the app with the setup vor VR... The app doesnt crash, it doesnt show any errors in LogCat and i tried to catch any Throwable but that didnt work either...
(On the App with no VR setup the exact same lines of codes works ...)
-> Android - Code:
public class UnityPlayerActivity extends Activity {
[...]
onCreate(Bundle savedInstanceState){
[...] //code generated by Unity
try{
Log.d("mDEBUG", "Test Android1");
UnityPlayer.UnitySendMessage("AndroidCommunication", "AndroidStudioInit", "false");
Log.d("mDEBUG", "Test Android2");
}catch(Throwable e){
e.printStackTrace();
}
}
//Function used by Unity - Code
public void unityLog(String msg){
Log.d("mDEBUG", "Unity: " + msg);
}
[...]
}
-> Unity - Code:
public void AndroidStudioInit(string flag)
{
bool sendCurCameraRotation = bool.Parse(flag);
AndroidJavaClass unityPlayerClass = new AndroidJavaClass("com.unity3d.player.UnityPlayer");
AndroidJavaObject unityPlayerActivity = unityPlayerClass.GetStatic<AndroidJavaObject>("currentActivity");
unityPlayerActivity.Call("unityLog", "AndroidStudio - Unity - Init");
}
-> Expected Outputs:
For both apps it should print in Logcat:
- "[...] D/mDEBUG: Test Android1"
- "[...] D/mDEBUG: Unity: AndroidStudio - Unity - Init"
- "[...] D/mDEBUG: Test Android2"
-> Actual Results:
For app without setup for VR:
- "[...] D/mDEBUG: Test Android1"
- "[...] D/mDEBUG: Unity: AndroidStudio - Unity - Init"
- "[...] D/mDEBUG: Test Android2"
For app with VR:
- "[...] D/mDEBUG: Test Android1"
- "[...] D/mDEBUG: Test Android2"
There are also no errors and the Unity App doesnt crash... it just "seems to ignore" the function call...