How can I fix my UI elements while having a Draggable Camera

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

Hello guys, im new to godot and im little helpless with my problem here…

So Iv’e made a UI Node which is set to “Full Rect” and added a Label on the Top-Left of the UI as you can see here:

Now I have a Camera-Script that makes my Camera able to drag around… so since the UI Node is a child of the Camera it gets dragged around as well which is a litte unfortunate

This is the Camera-Script

extends Camera2D

var _previousPosition: Vector2 = Vector2(0, 0)
var _moveCamera: bool = false

func _unhandled_input(event: InputEvent):
		if event is InputEventMouseButton && event.button_index == BUTTON_LEFT:
			if event.is_pressed():
				_previousPosition = event.position
				_moveCamera = true
			else:
				 _moveCamera = false;
		elif event is InputEventMouseMotion && _moveCamera:
			position += (_previousPosition - event.position)
			_previousPosition = event.position

Any ideas how i can fix this problem?

Use CanvasLayer node for UI.

Kirson | 2019-11-06 01:19

:bust_in_silhouette: Reply From: scorder

Add your Label as a child of CanvasLayer for it to move with the camera.
All UI elements that you need to move with the camera should be a child of CanvasLayer. You can also change the type of your root node to be a CanvasLayer.