#How to Access 2D Editor's Zoom Level (SOLVED solution in responses)

5 messages · Page 1 of 1 (latest)

ornate raptor
#

I'm not having a good time trying to access this. I need it to draw guidelines that will be visible at the same size no matter what zoom level I'm at in the 2D editor window. This has to happen in editor, not at runtime. I have the draw code and have it set up using a tool script and the setter of a variable to update it when that is changed. The best info I found pointed me toward EditorInteface.get_editor_viewport_2d(). The only trouble is, I can't access a "camera" for this. It returns null if I try, and there's no property of the viewport itself I'm aware of that I can use to scale my drawn guidelines.

If there's another easier way to draw guidelines that are always the same apparent thickness, regardless of zoom level, I'll glady do that instead. I'm not picky on this.

#

Welp, right after I posted this it occurred to me to link to the docs for the editor viewport, and it doesn't have a camera, but it's stuff can be access through its global_transform....Well, I have actually already tried this before attempting to access the camera...so..shoot.

#

Just tried: var thickness = (EditorInterface.get_editor_viewport_2d().global_canvas_transform.get_scale().x / 1.0) * 3.0 and that doesn't work at all, either. looking at other properties to see if one of them works.

ornate raptor
#

Still not finding a solution. I swear I've made something like this work before, but that might have been back in older version of Godot. Currently I'm in 4.2. It's not going to stop me from working on my game, but it's pretty annoying that it's not a fairly simple thing to hook into.

ornate raptor
#

SOLUTION:
I actually found one that works: var thickness = (EditorInterface.get_editor_viewport_2d().get_final_transform().x.x gives me a value I can use the inverse of for my scaling. so, Solved.