| Attention | Topic was automatically imported from the old Question2Answer platform. | |
| Asked By | Hohol_1227 |
I had tried to make it with ‘child_name.visible’, but it does not work.
Else, I need to make it, when I press the button (for example, KEY_ENTER)
| Attention | Topic was automatically imported from the old Question2Answer platform. | |
| Asked By | Hohol_1227 |
I had tried to make it with ‘child_name.visible’, but it does not work.
Else, I need to make it, when I press the button (for example, KEY_ENTER)
| Reply From: | tomeldee |
I think you can do this with any node in the way below (of course you have to replace the input name and nodename as well):
if Input.is_action_just_pressed("hide"):
if $nodename.visible == true:
$nodename.visible = false
else:
$nodename.visible = true
| Reply From: | tom555 |
Use the set_visible() method passing either true or false to hide or show respectively.
var child_node = $ChildNode
if Input.is_action_pressed("hide"):
child_node.set_visible(false)
| Reply From: | godot_dev_ |
Suppose your scene tree is configured as follows and you want to toggle the child2’s visibility
yourparent
child1
child2
By following this tutorial on input handling, it will help explain how to process a key press. This can be done as follows in the ‘yourparent’ node’s script, where every frame we check if a key (in this example, the enter key, which is mapped to the ‘ui_accep’ input event string) is pressed and call a function to toggle the visibility when the key is pressed
func _process(delta):
if Input.is_action_just_pressed("ui_accept"):
_on_toggle_child_visibility()
func _on_toggle_child_visibility():
var yourChild= get_node("child1/child2")
yourChild.visible = not yourChild.visible #toggle visibility
| Reply From: | Moreus |
In my project:
player.item_hand.Hide();
player.item_hand.DisableCollisions = true;
or
actionSprite.Visible = (input_action == Action.Action); // Action.Action is my Enum
[i]is CSharp but you can find same in GDscript
other option is just remove from tree and put back when needed.
You can use animation to control it too;