Mask Lite: a free 2D mask node that does not need to be the parent (Godot 4)

Godot’s clip_children only masks a node’s own children. Many 2D games need the other way round: a lamp that cuts a hole in a dark cover sitting on another CanvasLayer, a round portrait, a minimap with rounded corners. So here is a small free node for that, MIT.

MaskLite2D takes a target (any CanvasItem without its own material), a circle or a rounded box, a soft edge in pixels and an invert switch. The mask and its target can be in different branches of the scene, even on different CanvasLayers, and the editor shows the result live. Nothing is written into your scene: the target’s material stays empty.

var lamp := MaskLite2D.new()
lamp.size = Vector2(260, 260)
lamp.feather = 90.0
lamp.invert = true   # a hole in the dark instead of a window
add_child(lamp)
lamp.target = lamp.get_path_to($DarkCover)

The browser demo on the page has a dungeon lit by the mouse, and Tab shows six more uses made with the same node: a spyglass, a round minimap, health and mana orbs, a round portrait in a dialogue box, an x-ray window that follows a knight behind a wall, and a picture in picture.

One mask per target in this version. Tested on Godot 4.3 and 4.7, Forward+, Mobile and Compatibility, and on the web.