I have not used it much myself, but you might be able to use a CanvasLayer instead of a Viewport.
That will place the UI on it's own layer, which should make it just draw on top of whatever is on the screen. Due to the UI being drawn on top of the screen, if you use a CanvasLayer you will still likely need to reduce/remove the alpha on the health bar so the dark sections of the screen do not effect the visibility of the health bar.
As for the viewport and _unhandled_input
, how are you displaying the texture from the Viewport? It could be the node you are using for displaying the Viewport is catching the input events.
If you are trying to process Mouse events in _unhandled_input
and you are displaying the Viewport through a Control-based node, you can tell the mouse events to be passed by changing the Mouse Filter
property on the Control-based node. If you set it to ignore
, mouse events on that node will be ignored and should be able to be processed through _unhandled_input
.
If you are trying to process Keyboard events _unhandled_input
, then you'll probably need to pass events captured by the Control-based node to the Viewport. How you do this though, I have no idea. You might be able to pass events by overriding the gui_event function, but I have not done this myself so I don't know if it will work or not.
On the Viewport, you might be able to increase performance by changing the usage
(documentation) property to either 2D
or 2D no sampling
, depending on the needs of your project. Likewise, you probably want to set the disable_3d
property to true.
With those settings enabled, the Viewport node shouldn't attempt to initialize itself for 3D and run 3D related code. Without the 3D side of the Viewport enabled, performance should be a little better.
If you need 3D nodes for your UI, the only thing I can think of that might improve performance is to lower/disable MSAA on the Viewport and see if that helps. You could also try setting the usage
to 3D No Effects
and see if that helps.