Is there a hotkey to hide all unselected nodes in the scene?
Asked Answered
W

10

0

Hello! Sometimes I just need to focus on some nodes I'm working on the scene viewport.

Is there a hotkey to hide all unselected nodes in the scene? And is there a way to unhide all nodes in a scene?

Also if anyone could tell me a way to hide the navimesh overlay it would help a lot

Wye answered 13/11, 2023 at 16:56 Comment(0)
O
0

Farlee Well I just made a basic plugin skeleton that demonstrates the principle. It's easy to adapt and upgrade according to your needs. Simply check if a node has the visible property when toggling.

@tool
extends EditorPlugin

func _input(event):
	if event is InputEventKey and event.is_pressed() and event.keycode == KEY_H:
		var e = get_editor_interface()
		toggle_unselected_visibility(e.get_edited_scene_root(), e.get_selection().get_selected_nodes())
		
func toggle_unselected_visibility(node, selection):
	if not node in selection:
		if "visible" in node:
			node.visible = not node.visible
	for child in node.get_children():
		toggle_unselected_visibility(child, selection)

Also toggling via the same hotkey probably isn't the best modality as it'd mess things up when you change the selection. But again, easy to change the logic to fit your particular workflow. As a homework, someone should make a version with 2 hotkeys; one for hiding and other for showing.

Overtly answered 14/11, 2023 at 0:47 Comment(0)
T
0

Wye Not that I am aware of.

Thrawn answered 13/11, 2023 at 17:1 Comment(0)
O
0

Wye No but it'd be easy to write an editor plugin script that does it.

Overtly answered 13/11, 2023 at 17:4 Comment(0)
O
0

Wye
There you go. For simplicity I hardcoded hotkey H to toggle visibility of unselected nodes

@tool
extends EditorPlugin

func _input(event):
	if event is InputEventKey and event.is_pressed() and event.keycode == KEY_H:
		var e = get_editor_interface()
		toggle_unselected_visibility(e.get_edited_scene_root(), e.get_selection().get_selected_nodes())
		
func toggle_unselected_visibility(node, selection):
	if not node in selection:
		node.visible = not node.visible
	for child in node.get_children():
		toggle_unselected_visibility(child, selection)
Overtly answered 13/11, 2023 at 17:17 Comment(0)
W
0

Overtly Thank you Petes ! I have never added a plugin to a godot project. I have searched on how to add a hotkey script like this but could not find. Could you explain how can I do this?

Wye answered 13/11, 2023 at 20:0 Comment(0)
O
0

Wye Project Settings -> Plugins -> Create New Plugin. Fill in the details and Godot will create a new boilerplate script. Paste the code and you're done.

Overtly answered 13/11, 2023 at 20:3 Comment(0)
W
0

Overtly Hm... it did not work here. I think I did something wrong.

Wye answered 13/11, 2023 at 23:59 Comment(0)
O
0

Wye Try to reload the project.

Overtly answered 14/11, 2023 at 0:5 Comment(0)
F
0

Overtly There you go.

If there is an undisplayed node in the project, the script gives an error. But it continues to work. In my case — "Timer":

res://addons/hideunselectednodes/hide_unselected_nodes.gd:11 - Invalid get index 'visible' (on base: 'Timer').
Farlee answered 14/11, 2023 at 0:36 Comment(0)
O
0

Farlee Well I just made a basic plugin skeleton that demonstrates the principle. It's easy to adapt and upgrade according to your needs. Simply check if a node has the visible property when toggling.

@tool
extends EditorPlugin

func _input(event):
	if event is InputEventKey and event.is_pressed() and event.keycode == KEY_H:
		var e = get_editor_interface()
		toggle_unselected_visibility(e.get_edited_scene_root(), e.get_selection().get_selected_nodes())
		
func toggle_unselected_visibility(node, selection):
	if not node in selection:
		if "visible" in node:
			node.visible = not node.visible
	for child in node.get_children():
		toggle_unselected_visibility(child, selection)

Also toggling via the same hotkey probably isn't the best modality as it'd mess things up when you change the selection. But again, easy to change the logic to fit your particular workflow. As a homework, someone should make a version with 2 hotkeys; one for hiding and other for showing.

Overtly answered 14/11, 2023 at 0:47 Comment(0)
W
0

Overtly It worked now. Thanks a lot!

Wye answered 14/11, 2023 at 2:2 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.