Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
1
Question by SolidSnake · Jul 17, 2013 at 01:11 PM · androidtransparentunityplayer

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

Comment
Add comment · Show 4
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image AlexanderProphet · Sep 10, 2015 at 06:12 PM 0
Share

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.

avatar image richiejk_ctct AlexanderProphet · Feb 05, 2016 at 01:51 AM 0
Share

Any update on this?

avatar image zjj · Sep 06, 2016 at 10:43 AM 0
Share

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?

avatar image sbodi · Sep 15, 2016 at 05:05 PM 0
Share

Hey,

Did you find any solution for this? I am looking for same solution for Unity 5.x.

Regards, Satish

2 Replies

· Add your reply
  • Sort: 
avatar image
1
Best Answer

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)

Comment
Add comment · Show 8 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image thorikawa · Dec 03, 2013 at 08:00 AM 0
Share

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?

avatar image SolidSnake · Dec 09, 2013 at 12:46 PM 1
Share

@thorikawa I haven't tried it yet with Unity 4.3 I will let you know if I found something

avatar image Bunny83 · Dec 09, 2013 at 12:56 PM 0
Share

@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.

avatar image SolidSnake · Dec 09, 2013 at 01:04 PM 0
Share

@Bunny83 good point I've updated the answer with Unity's version

avatar image Infrid · Feb 10, 2014 at 04:51 PM 0
Share

What's the verdict with unity 4.3? is it possible? Or should I ask a separate question with that specific version?

Show more comments
avatar image
0

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...)

Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image SolidSnake · May 19, 2015 at 09:36 AM 0
Share

Hi @RotemAV ... from your description I guess it could be the shader you are using? did you try $$anonymous$$obile diffuse?

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

23 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

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


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges