- Home /
UnityPlayer as a SubView with Transparent Background?
Hello All,
I am trying to do the following on Android (then possibly on iOS) and any advices will be appreciated:
Overlaying UnityPlayer view on top of Native Android view where only the 3D objects being drawn and no camera background (transparent background)
My current progress:
So far I managed to use my Unity project as library into another Android project and assign UnityPlayer view to a FrameLayout on top of another Android view but the camera background color showing... I tried changing the clear flag option to depth only but it didn't work.
I also managed to use a separate GLSurfaceView which I assigned class extending UnityPlayer and implementing GLSurfaceView.Renderer to as the renderer but I am still getting opaque background.
My code as follows:
// the class extending the player
class CustomUnityPlayer extends UnityPlayer implements GLSurfaceView.Renderer {
public CustomUnityPlayer(ContextWrapper context) {
super(context);
}
public void onDrawFrame(GL10 gl) {
super.onDrawFrame(gl);
}
}
// inside OnCreate function:
m_UnityPlayer = new CustomUnityPlayer(this);
int glesMode = m_UnityPlayer.getSettings().getInt("gles_mode", 1);
m_UnityPlayer.init(glesMode, false);
mUnityView = new GLSurfaceView(getApplication());
mUnityView.setEGLContextClientVersion(2);
mUnityView.setZOrderOnTop(true);
mUnityView.setZOrderMediaOverlay(true);
mUnityView.setEGLConfigChooser(8, 8, 8, 8, 16, 0);
mUnityView.setRenderer(m_UnityPlayer);
mUnityView.getHolder().setFormat(PixelFormat.TRANSLUCENT);
setContentView(R.layout.activity_fullscreen);
FrameLayout layout = (FrameLayout) findViewById(R.id.UnityView);
LayoutParams lp = new LayoutParams(LayoutParams.FILL_PARENT,
LayoutParams.FILL_PARENT);
layout.addView(mUnityView, 0, lp);
Am I missing something and is it even possible? Any help will be much appreciated.
Thanks alot
Has anyone found a solution to this for Unity 5.2? I'm looking for a way to implement a transparent background behind the Google Cardboard UI.
ii followed your solution and is background is transparent, but the objects(3d model and ui) in unity scence doesn't show, what should I do?
Hey,
Did you find any solution for this? I am looking for same solution for Unity 5.x.
Regards, Satish
Answer by SolidSnake · Jul 18, 2013 at 09:08 AM
After several attempts... removing mUnityView.setZOrderMediaOverlay(true); did the trick for me. (Tested on Unity 4.2)
Hi, I am using Unity 4.3.0f4 and it does not work because UnityPlayer no longer implements GLSurfaceView.Renderer class. Not UnityPlayer is just a subclass of FrameLayout and it holds SurfaceView internally. Do you have any work around for it?
@thorikawa I haven't tried it yet with Unity 4.3 I will let you know if I found something
@SolidSnake: Could you add to your answer what version of Unity you had been using where it still worked? That would make the answer much more valuable for others.
Also if someone tries this on a newer version where it works as well, please leave a comment with the exact Unity version.
@Bunny83 good point I've updated the answer with Unity's version
What's the verdict with unity 4.3? is it possible? Or should I ask a separate question with that specific version?
Answer by RotemAV · May 18, 2015 at 10:35 AM
Hi i followed you're (SolidSnake) solution and the background is transparent... but the shadow side of the cube is also transparent... like the image show on my previews post (Apr 17 at 10:54 AM)... i tried anther scene with more 3d objects, most of them has the same affect as the cube and some do not... any solution for this? (i am newbie with unity...)
Hi @RotemAV ... from your description I guess it could be the shader you are using? did you try $$anonymous$$obile diffuse?
Your answer
Follow this Question
Related Questions
Is there any way to create a transparent view on Android? 0 Answers
Transparency Diffuse Problem 0 Answers
Crash: cutout shaders on mobile 1 Answer
Transparent texture not rendering over video overlay on Android 0 Answers
Transparent Detail on mobile 0 Answers