As part of an AR project for a client, we need to to overlay a UnityPlayer on Android on top of a camera feed from Vuforia. We originally opted to not use the Unity plugin from Vuforia as we also need to shuttle Vuforia image captures to a 3rd party barcode scanning library, and had hoped to only incur the memory and processor footprint of Unity once an AR target was identified by Vuforia. We additionally have native components (views) which we need to overlaid on top of the the unity player.
The general approach we followed is documented here : UnityPlayer as a SubView with Transparent Background? - Questions & Answers - Unity Discussions Change the zOrderOnTop flag and the background transparency on the GlSurfaceHolderView, and do use the UnityPlayer as the renderer. Here is a working example of this, where the Red background is visible behind the unity object:
Example Source Code is available here: ShareFile Login
This approach is working for us on Unity 4.2.2f1 However, in Unity 4.3 and up, Unity changed the architecture so that rendering occurs natively and without the UnityPlayer implementing GLRenderer. We would release our working app on Unity 4.2.2f1, however, it contains libraries have Text relocations which means they can’t run on Run level 23 on Android (Marshmallow), which we now need to support.
We hence are exploring the transparent unity view on top of a native Android view on Unity5, which does not suffer from the text relocation issue, and would be the preferable future solution. As the GLSurfaceView renderer is not exposed in this version, we tried reflection to gain access to it, and also tried to use blend modes, although these don’t appear to work with SurfaceViews. The non working example of this can be found here: ShareFile Login
Attempted Unity5 Transparent background camera approach: (not transparent)
Does anyone have any pointers on how to
-
An approach to overlay a UnityPlayer on-top of a native Android view in Unity 5.3.2f1 or above? (related to UnityPlayer as a SubView with Transparent Background? - Questions & Answers - Unity Discussions)
What I’ve tried:
a) Using reflection to modify the underlying surface view to set the ZOrderOnTop flag.
b) Using reflection to the modify the underlying surface view background paint
c) Changing the blend mode of the layer paint on the underlying surface view. -
Alternately, anyone have a solution to text relocations on a 4.2.x version which is compatible with Marshmallow?
Target Run Level 22:
07-26 13:09:32.393 8229-8229/? W/linker: /data/app/com.sample.app/lib/arm/libmain.so has text relocations. This is wasting memory and prevents security hardening. Please fix.
07-26 13:09:32.399 8229-8229/? W/linker: /data/app/com.sample.app/lib/arm/libmono.so has text relocations. This is wasting memory and prevents security hardening. Please fix.
07-26 13:09:32.487 8229-8229/? W/linker: /data/app/com.sample.app/lib/arm/libunity.so has text relocations. This is wasting memory and prevents security hardening. Please fix.
Target Run Level 23:
Caused by: java.lang.UnsatisfiedLinkError: dlopen failed: /data/app/com.sample.app/lib/arm/libmain.so: has text relocations
at java.lang.Runtime.loadLibrary(Runtime.java:372)
at java.lang.System.loadLibrary(System.java:1076)
at com.unity3d.player.UnityPlayer.a(Unknown Source)
at com.unity3d.player.UnityPlayer.(Unknown Source)
at com.sample.app.UnityPlayerSubclass.(UnityPlayerSubclass.java:12)
at com.sample.app.UnityViewWrapperImpl.setupView(UnityViewWrapperImpl.java:37)
at com.sample.app.UnityViewWrapperImpl.(UnityViewWrapperImpl.java:32)
at com.sample.app.UnityWrapperImpl.createUnityView(UnityWrapperImpl.java:17)
Thanks,
Ben