Godot Version
4.2
Means you want to add zoom in/out system in your game or editor by codes?
I believe the question is, when making an addon, how to get the current zoom level of the editor window. I’m not entirely sure but I did have to use a similar code before when working with shader values, take a look here, it’s C# but I imagine it might help you:
SetZoom(Engine.IsEditorHint()
? GetViewport().GlobalCanvasTransform.Y.Y
: GetViewport().CanvasTransform.Y.Y);
If I remember correctly, it is GetViewport().GlobalCanvasTransform
No, I want to get the zoom value in the editor (I indicated it in the screenshot). I don’t need a zoom in/out system in the game. I remember digging through plugin-related documentation for a long time ago and kind of even found something I needed now, but I can’t find it now.
Try get_viewport().get_final_transform().x.x
Here’s a tool that prints your editor’s zoom (underlined in red in first post) every time it changes:
@tool
class_name ZoomGetter
extends Node2D
var lastZoom : float = 0.0
var vp : Viewport = null
func _process(delta):
if Engine.is_editor_hint():
var newZoom
if vp == null:
vp = get_viewport()
print("zoom getter vp set")
newZoom = vp.get_final_transform().x.x
if lastZoom != newZoom:
print( "%f" % newZoom )
lastZoom = newZoom
This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.