However, any UI elements in the sub-viewport can’t be interacted with, and that’s a big no-no. I’ve tried viewport.push_input(...), but it doesn’t seem to be working. I can only assume that this is because the GUI elements are a child of a Node2D?
So, I was wondering if there’s a way to have dynamic, interactive GUI elements around a 3D object (if the character moves, so does the GUI).
Also, I have some concerns with how this might be implemented:
In a 2D scene, I have a system in place that draws a line between two GUI elements by grabbing their position in respect to the screen. However, since this method involves get_viewport(), I’m afraid this might break functionality when using a SubViewport.
It is… quite annoying positioning everything in a SubViewport.
Anytime I add child to the Viewport and try to adjust it’s positioning, it takes me to the 2D renderer window but I can’t see anything. Not that big of a deal, just wondering if I’m missing something…
In my case, I made to where the keyboard is used to switch focus between the UI element:
I used push_input for this
func _input(event):
if c_mode == 1:
if subvterminal:
subvterminal.push_input(event)
but you want to be able to click on the elements on the screen.
since the elements are in 2D and not perspective, you can put your 2D elements as children of the 3D objects (no need for viewports), and then position them using is_position_behind and unproject_position:
func _process(_delta):
if cam.is_position_behind(unit.get_head_position()):
visible = false
else:
visible = true
var posish : Vector2 = cam.unproject_position(unit.get_head_position())
posish.y -= y_shift
posish.x -= hhwidth
position = posish
edit: if you want the elements to be in perspective, you’ll have to create them using 3D nodes and Area3Ds for clicking. then:
You can make a 3D plane, then make the character a texture on the plane. Then you can add a regular collision shape to the plane to make it interactable.