-
-
Notifications
You must be signed in to change notification settings - Fork 97
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add ability to toggle collision shape visibility in-game #11790
Comments
This would be awesome! For the meantime, here is some workaround code I "borrowed" from the PankuConsole addon and currently use in my active project: # Currently godot can't toggle visibility of 2D collision shapes at runtime, this is a workaround.
# See https://github.com/godotengine/godot-proposals/issues/2072
func toggle_2d_collision_shape_visibility() -> void:
var tree := core.get_tree()
tree.debug_collisions_hint = not tree.debug_collisions_hint
# Traverse tree to call queue_redraw on instances of
# CollisionShape2D and CollisionPolygon2D.
var node_stack: Array[Node] = [tree.get_root()]
while not node_stack.is_empty():
var node: Node = node_stack.pop_back()
if is_instance_valid(node):
if node is CollisionShape2D or node is CollisionPolygon2D:
node.queue_redraw()
node_stack.append_array(node.get_children())
core.notify("2D Debug Draw: " + str(tree.debug_collisions_hint))
# Currently godot can't toggle visibility of 3D collision shapes at runtime, this is a workaround.
# See https://github.com/godotengine/godot-proposals/issues/2072
func toggle_3d_collision_shape_visibility() -> void:
var tree: SceneTree = get_tree()
# https://github.com/godotengine/godot-proposals/issues/2072
tree.debug_collisions_hint = not tree.debug_collisions_hint
print("Set show_debug_collisions_hint: ", tree.debug_collisions_hint)
# Traverse tree to call toggle collision visibility
var node_stack: Array[Node] = [tree.get_root()]
while not node_stack.is_empty():
var node: Node = node_stack.pop_back()
if is_instance_valid(node):
if node is RayCast3D \
or node is CollisionShape3D \
or node is CollisionPolygon3D \
#or node is CollisionObject3D \
or node is GPUParticlesCollision3D \
or node is GPUParticlesCollisionBox3D \
or node is GPUParticlesCollisionHeightField3D \
or node is GPUParticlesCollisionSDF3D \
or node is GPUParticlesCollisionSphere3D \
or node is CSGPrimitive3D:
# remove and re-add the node to the tree to force a redraw
# https://github.com/godotengine/godot/blob/26b1fd0d842fa3c2f090ead47e8ea7cd2d6515e1/scene/3d/collision_object_3d.cpp#L39
var parent: Node = node.get_parent()
if parent:
parent.remove_child(node)
parent.add_child(node)
node_stack.append_array(node.get_children()) There is a drawback to this workaround however, due to the collision nodes leaving and entering the tree, collision events will occur again eg: the player is standing in an Area2D/3D, the area will fire it's signals again. EDIT: After looking back at it again I realized that the PankuConsole just has the 2d version of that, so the 3d version comes from me ^^ |
Describe the project you are working on
Just a game where I sometimes need to see what the collision shapes look like. Aka, most games.
Describe the problem or limitation you are having in your project
It's annoying to have to exit the the game, go into the debug menu, and enable visible collision shapes, then rerun the game. After that you have to do the same thing to disable them. This whole process if very tedious.
Describe the feature / enhancement and how it helps to overcome the problem or limitation
In 4.4 we have the nice UI around the running game which adds some great features. I think there could be a button somewhere there to enable/disable collision shapes. This would make sense because one might want to select those shapes.
Describe how your proposal will work, with code, pseudo-code, mock-ups, and/or diagrams
In the tab up here, there would be a button probably in a dropdown that's called "Toggle visible collision shapes" which would do just that.
If this enhancement will not be used often, can it be worked around with a few lines of script?
For all I know it could not, and it would be used often.
Is there a reason why this should be core and not an add-on in the asset library?
Toggling visible collision shapes is a core part of the editor, all this would do is make it a lot more convenient.
The text was updated successfully, but these errors were encountered: