Skip to content

Remove magic debug color from RayCast3D and ShapeCast3D #14139

@Scrawach

Description

@Scrawach

Describe the project you are working on

Describe the problem or limitation you are having in your project

Describe the feature / enhancement and how it helps to overcome the problem or limitation

RayCast3D and ShapeCast3D use magic Color(0, 0, 0, 1) as default. Every time, when you set up this color as debug custom color, RayCast3D and ShapeCast3D ignore it and use debug color from ProjectSettings.

Code from RayCast3D and ShapeCast3D:

Color color = debug_shape_custom_color;
if (color == Color(0.0, 0.0, 0.0)) {
	// Use the default debug shape color defined in the Project Settings.
	color = get_tree()->get_debug_collisions_color();
}

As result, in inspector we see black color, but in editor window - another, from ProjectSettings. At first time it's looks like a bug (archieved issue about it: godotengine/godot#102611)

Yes, It's has extra note in documentation, but it's a bit confuse anyway and I'm sure, that we can easy avoid it.

Another point is that other nodes with debug color not have a magic color (as example, CollisionShape3D, CollisionPolygon3D, CollisionShape2D). And it's work fine. I think this small enhancement in QoL is worth it.

Describe how your proposal will work, with code, pseudo-code, mock-ups, and/or diagrams

Instead of check magic color every time, we can just re-use code from CollisionShape3D (or another debug shapes, it's similar) and cached debug color from ProjectSettings in constructor:

Color RayCast3D::_get_default_debug_color() const {
	const SceneTree *st = SceneTree::get_singleton();
	return st ? st->get_debug_collisions_color() : Color(0.0, 0.0, 0.0, 0.0);
}

RayCast3D::RayCast3D() {
	debug_shape_custom_color = _get_default_debug_color();
}

It will also require some additional property validation work.

If this enhancement will not be used often, can it be worked around with a few lines of script?

No.

Is there a reason why this should be core and not an add-on in the asset library?

Debug color is set from core.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions