Godot-Android-Samples icon indicating copy to clipboard operation
Godot-Android-Samples copied to clipboard

Is it possible to make it transparent behind the 3D models?

Open lonevox opened this issue 6 months ago • 2 comments

I'm wanting to have essentially Godot overlayed in my android app so I can add 3D objects above my android UI. Messing around with your gltf demo, I can't seem to make Godot's background transparent. I'm not familiar with Android development at all so maybe you know the solution.

I have enabled these Godot project settings for a transparent background (not sure if it makes a difference, but I've opened the Godot project in Godot 4.5 so these settings might work differently in 4.2):

  • display/window/per_pixel_transparency
  • display/window/size/transparent
  • rendering/viewport/transparent_background

Running the Godot project from the editor, I correctly get a transparent background on Linux:

Image

However, on Android the background shows as black (I've added an image behind the Godot fragment container so I should be able to see it if Godot's background is transparent):

Image

I thought that potentially adding android:background="@android:color/transparent" to the Godot fragment container would fix the issue, but it didn't:

<FrameLayout
            android:id="@+id/godot_fragment_container"
            android:layout_width="match_parent"
            android:layout_height="300dp"
            android:background="@android:color/transparent" />

Any ideas?

lonevox avatar May 21 '25 06:05 lonevox

I believe this could be a bug in Godot, so I've made an issue there: https://github.com/godotengine/godot/issues/106703

lonevox avatar May 22 '25 02:05 lonevox

@lonevox You're correct, that's a bug. You can use the following workaround in your code until the issue is fixed:

override fun onStart() {
        super.onStart()

        godotFragment?.view?.let {
            Log.d("FHK", "Checking for Godot surface view")
            for (view in it.allViews) {
                if (view is SurfaceView) {
                    Log.d("FHK", "FHK - Found Godot surface view")
                    view.setZOrderOnTop(true)
                    view.holder.setFormat(PixelFormat.TRANSLUCENT)
                    break
                }
            }
        }
    }

The workaround retrieves the Godot's SurfaceView and updates its flags to allow for transparency.

m4gr3d avatar May 22 '25 03:05 m4gr3d