I would like to make an EditorPlugin that has draggable points that snap to the 2d canvas grid. Plugins like Path2DEditor, CollisionPolygon2DEditor, Line2DEditor, ect, all use CanvasItemEditor.snap_point() to snap to the grid. I don't think there is a good way to even get the snap settings alone in gdscript. Right now I use get_editor_interface().get_base_control(), then I recursively search through all the child nodes to find the SnapDialog and the MenuButton with "Edit" text. Then I read all the snap settings directly from the UI so I can make my own snap_point(). Would be very convenient if these functions were available in some way to GDscript.
I'm currently working on improving this function to perform smart snapping. I can make it available to gdscript on the way.
This ended up more diffcult than I though to implement. It needs the editor classes to be available to GDscript which is not the case yet. Should be done but only when 'tool' is set in a script.
@groud Have you figured it out?
Well I'm not sure it is clear enough for it to be exposed. I'll have a look someday.
I'm having this issue as well, the lack of these functions makes creating custom nodes with editable settings really annoying.
+1, this is pretty important to have access to for both 2D and 3D tools.
I would like to make custom snap settings (for a hex grid) would that be covered in what you're doing here @groud, or should I create a new issue?
Handling a hex grid requires a rework of the grid system, it's unrelated to this issue.
@groud What's the status on this issue?
@groud What's the status on this issue?
Not done yet ^^. However, I'd like to have a simple way to declare functions as editor (or tool scripts) only, I am not sure it can be done in a clean way for now.
@efirdc Did you find the function/variable that gets the snap settings by any chance? I'm looking for a way for my plugin such that when Configure Snap > Grid Step is set, it'll then set the snap settings in, say, a TileMap in the process.
[UPDATE] Nvm found the question/solution in which then links to this topic: https://godotengine.org/qa/18051/tool-script-in-3-0
I had to do some pruning refactoring as some variables become null in the process.
Anyone wondering about the last missing steps for this mentioned hack - how to apply the values - the key is to set the values to the SpinBox controls and then press the OK button of the SnapDialog virtually (no need to popup):
For example, horizontal grid size to 100: spin_boxes[2].set_value(100), and to apply: snap_dialog.get_ok().emit_signal("pressed").
Documented the stuff here:
https://godotengine.org/qa/39440/can-i-get-snap-settings-in-a-script?show=79083#a79083
Most helpful comment
I'm currently working on improving this function to perform smart snapping. I can make it available to gdscript on the way.