Return an object instead of a dictionary for the function intersect_ray() #7845
Replies: 3 comments 1 reply
-
Because in comparison, creating a whole new Object is comparatively slower than returning a Dictionary. Fun fact, this very exact |
Beta Was this translation helpful? Give feedback.
-
2 follow-up questions,
|
Beta Was this translation helpful? Give feedback.
-
For the C# API, it could return a struct which internally wraps the existing dictionary. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
When using the function PhysicsDirectSpaceState2D.intersect_ray(), the return result is a dictionary. The dictionary makes it very difficult to understand the result while in the editor unless you have access to the documentation. Without that prior knowledge or access, it is impossible to know what strings you need to use to get the information. Additionally, typing a string is prone to typos, allowing code to compile but not work as intended. Also, in C#, you need to cast each element to its corresponding type, adding another layer of obfuscation to the process.
I propose the function instead returns an object named something like RaycastHit or RaycastInfo, which has the same Properties as the returned dictionary (position, normal, collider, collider_id, rid, shape, metadata). This way, IntelliSense would also work, speeding up production and eliminating the guessing game of how to access the variables.
intersect_ray() Documentation
I did find the following issues, but no discussions yet talking about this.
#4474
#7661
I guess one question, to start a discussion, is why does Godot return a dictionary instead of a class/ object?
Beta Was this translation helpful? Give feedback.
All reactions