godotengine / godot-proposals

Godot Improvement Proposals (GIPs)
MIT License
1.16k stars 97 forks source link

Enable physics_object_picking_sort for main viewport by default #6721

Open Emreu opened 1 year ago

Emreu commented 1 year ago

Describe the project you are working on

2D game with objects picking (i.e. jigsaw puzzle)

Describe the problem or limitation you are having in your project

Usually descendants of CollisionObject2D is used for picking in 2D games, but in case of overlapping collision shapes order of mouse event processing is nondeterministic. This complicates logic for detecting which object is on top of another. Viewport has property physics_object_picking_sort which solves problem, but for root viewport it could be enabled only via code.

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

Enabling property by code only is not a clear design imo, especially since SubViewport has nice and accessible property in inspector. So it would be great to have physics_object_picking_sort enabled by default for root viewport or have configuration parameter in project settings.

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

You just put a checkbox in project settings and events become nicely sorted.

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

Yes, script solve the problem, but more thoughtful defaults or accessible configuration is much better.

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

For 2D games it's essential. I looked through many posts with same problem (inconsistent order of events) and quirky workaround solutions.

Calinou commented 1 year ago

The feature is likely disabled by default since it has a performance overhead. This should be added as an opt-in project setting to avoid any performance impact on existing projects.

See this PR for an example of adding a project setting to toggle a root Viewport property: https://github.com/godotengine/godot/pull/67104