I have a 3D game in which I made a computer screen that I want to make able to take input using a LineEdit node - terminal based. But I cannot focus on the LineEdit node for some reason while in my 3D character.
How do I do this? Help.
Thanks.
Take input with LineEdit.
You are using a viewport for it, yes? I think there's a togglable property to enable/disable input. There might even be multiple relevant properties perhaps.
Megalomaniak I tried that. It does select the LineEdit node, the caret appears, but it still won't take input. I might be missing a step, if you could help that'd be nice, thank you.
Check Debugger >> Misc >> Clicked Control to see if another Control is getting the input.
DaveTheCoder
What am I looking at?
The two errors are:
get_node: Node not found: "Display/DisplayTexture/SubViewport" (relative to "Screen").
setup_local_to_scene: ViewportTexture: Path to node is invalid.
But I don't know what's causing them. I have the paths done right and all.
Thank you for the reply!
You might have to handle and pipe the input from the (sub-)viewport to the node manually perhaps. On the page I linked in my previous post there should be a bunch of demos linked. Exploring some of these might be enlightening perhaps. Beyond that I sadly don't really have much more to offer since I haven't needed or built anything quite like this for my own projects before.
- Edited
I've found a solution. Search about the Viewport class' "push_input" and the "push_text_input" methods. Here's a project I've found that uses this method gracefully. https://github.com/godotengine/godot-demo-projects/blob/master/viewport/gui_in_3d/gui_3d.gd line 46 at the time of writing.
push_input simply passes on the input from a parent viewport to a subviewport. Combining with "get_viewport().set_input_as_handled()" we can prevent unwanted player input. An example from my project (code was simplified):
func _input(event: InputEvent) -> void:
if not _locked_player: # Only register input if the player is sat at the computer terminal
return
if event.is_action_pressed(key_bind_escape): # Quit terminal if press Esc
_locked_player.MOVEMENT_COMPONENT.activate()
_locked_player.CAMERA_COMPONENT.activate()
_locked_player.CAMERA_COMPONENT.reset_fov()
_locked_player = null
# this method calls release_focus on all child control nodes. SCREEN is within the subviewport
SCREEN.remove_focus()
# Consume the input
# (since it's a FPS game, ESC also frees the mouse. We can prevent this by calling this method)
get_viewport().set_input_as_handled()
return
$SubViewport.push_input(event)
get_viewport().set_input_as_handled()
I hope this answer is useful. Just made this account to share this info. Please share this in other forums as well, it seems very people know about this.
DaveTheCoder OMG. TY for this. Why did I not know about this feature??? You saved me from myself, and my thinking I had to go through and check all 47 control type nodes manually to see what was getting clicks. Turns out, "pass" didn't actually pass when it was the mouse property for Control Nodes. I had to set the Control Nodes (green circles) to "Ignore", otherwise they were grabbing clicks from things that were even set to Stop. This feature...in debugger Misc tab...is the best thing of the century. So, DaveTheCoder, thank you from MeTheNotAtAllACoder. I owe you at least 100 hours of my future time. If I can do anything to repay you, please just ask.