How can I set a Transparent Background in Godot4.0

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By Madline

I set

display/window/per_pixel_transparency/allowed = true
display/window/size/transparent = true
rendering/transparent_background = true
application/boot_splash/bg_color = Color(0, 0, 0, 0)

But the background is black NOT transparent!
Even if I written in the script for the root node of
func _ready() : get_viewport().transparent_bg = true”.

In Godot3, I set

display/window/per_pixel_transparency/allowed = true
display/window/per_pixel_transparency/enabled = true

And I written in the script for the root node of
func _ready() : get_viewport().transparent_bg = true”.
Then,
the background is transparent.
But it doesn’t work in Godot 4.
Why?

I tried to find the answer in github but nothing.
Is this a bug?

Godot4.0 beta5 win64
Windows10 Home 22H2
AMD Ryzen 7 5800H
NVIDIA GeForce RTX 3050 Laptop

:bust_in_silhouette: Reply From: Gluon

If you go into the project settings and tick the following boxes

project>project settings> tablet driver > borderless
project>project settings>per pixel transparency> allowed
project>project settings>per pixel transparency> enabled

if they are ticked then the code you wrote

func _ready() : get_viewport().transparent_bg = true

should work.

Yeah!
In Godot3, it’s right.
BUT!
In Godot4, it doesn’t work.

Madline | 2022-11-24 07:04

:bust_in_silhouette: Reply From: Noita

I am reviving this to answer for anyone else looking for a solution for godot 4.

1: Project Settings > Display > Window > Size > Transparent = true
2: func _ready: get_viewport().transparent_bg = true

Not working for me, I tried like everything but still same, I think is a bug.

Ytachi1000 | 2023-03-16 07:22

:bust_in_silhouette: Reply From: tosan

This works on …
Godot version: 4.0.2
Modes: Forward+, Mobile, Compatibility
Plattform: Kubuntu 22.04
GPU: Ryzen 5600G / RX Vega 7

Re-enable per-pixel transparency support on Linux, macOS, and Windows. #65283


Editor: Project>Settings>Display>Window>Per Pixel Transparency>Allowed>On
Main scene root node GDscript:

func _ready():
  get_tree().get_root().set_transparent_background(true)
  DisplayServer.window_set_flag(DisplayServer.WINDOW_FLAG_TRANSPARENT, true, 0)
  #DisplayServer.window_set_flag(DisplayServer.WINDOW_FLAG_MOUSE_PASSTHROUGH, true, 0)
  #DisplayServer.window_set_flag(DisplayServer.WINDOW_FLAG_ALWAYS_ON_TOP, true, 0)
  #DisplayServer.window_set_flag(DisplayServer.WINDOW_FLAG_BORDERLESS, true, 0)

CSharp:

public override void _Ready() {
GetTree().Root.TransparentBg = true;
DisplayServer.WindowSetFlag(DisplayServer.WindowFlags.Transparent, true, 0);
//DisplayServer.WindowSetFlag(DisplayServer.WindowFlags.MousePassthrough, true, 0);
//DisplayServer.WindowSetFlag(DisplayServer.WindowFlags.AlwaysOnTop, true, 0);
//DisplayServer.WindowSetFlag(DisplayServer.WindowFlags.Borderless, true, 0);
}
2 Likes