Make children nodes of a SubViewport collide with nodes outside of it

Godot Version

4.4

Question

I have this setup where I spawn some objects as children of a SubViewport (with transparent background), because I have a ShaderMaterial on it that should affect only objects inside that SubViewport.

However, I’d like to have these objects to collide with other nodes, but from my understanding, they will collide only with other nodes under the same SubViewport.

My current setup - Droplets are being spawned dynamically, Sprite2D2 is just a placeholder node to check if sprite outside SubViewport is not affected by the ShaderMaterial (and it’s not, yaay) and StaticBody2D is a node that I’d like to have outside that SubViewport:

This makes a little mess in my nodes hierarchy, since for collisions I’d have to place all my nodes under the SubViewport, where I only need some specific ones. If I move the StaticBody2D outside the SubViewport, then (unsurprisingly) the droplets don’t collide with it.

I’m not a shader expert, so maybe it’s just my approach that’s wrong here?

I’m pretty sure each viewport contains its own World2D, so you want to do something like

SubViewport.World2D = GetViewport().World2D;

See “Worlds” section in:

(Edit to clarify this is true of 2D viewports; for 3D the default is the opposite – they don’t have their own World3D.)