Clickable Control Buttons in 3D Space

Godot Version

v4.3.stable.official [77dcf97d8] (MacOS)

Question

I am trying to place multiple clickable Control Buttons in a 3D space — How can I do this? This seems relativley simple but I’m unable to figure it out. Any help would be appreciated.

Here is what I have right now:

Screenshot 2024-12-29 at 7.19.59 PM

I created a MeshInstance3D and set the mesh to a QuadMesh. The material overide is a local-to-scene StandardMaterial3D, with a ViewportTexture set to the SubViewport. This renders it in the scene, but it does not provide interactivity.

Local script under button 1:

extends Button

func _ready() -> void:
	pressed.connect(func():
		print("CLICK")
	)

Console

Not getting the “CLICK” message. No obviously-solved errors, but there’s these weird ones which seem relevant:

Other Attempts

I thought about using a static body and detecting clicks (as suggested here), but that wouldn’t allow for multiple buttons. So I thought I could to convert the input_event’s click_position to a relative Vector2(0-1, 0-1), which worked, but I wasn’t sure how to convert that into the actual button inside the viewport. This method also seems bad because I would have to manually program more functionality later on (like mouse hovers).

I tried using a Sprite3D, but also got no interaction.

Basically you should use an Area3D, that acts as an interface between the main root viewport (the 3D world) and your SubViewport (the 2D Gui) and that detects mouse-clicks in the 3D world.
You can find a demo project here: godot-demo-projects/viewport/gui_in_3d at master · godotengine/godot-demo-projects · GitHub or in the asset library: GUI in 3D Viewport Demo - Godot Asset Library.
It also shows how to convert the coordinates of the mouse click in the 3D world to the appropriate coordinates in the 2D Gui.

1 Like

That Viewport Texture must be set to use it error will be fixed in 4.4 iirc, either way it does not impact the logic itself.

1 Like