-
-
Notifications
You must be signed in to change notification settings - Fork 21.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Editor viewport global_canvas_transform auto reset when mouse hover on viewport #57898
Comments
Finally I figure it out that you cannot change canvas item editor position by set the viewport's global_canvas_transform. I think the document should be point it out maybe. Canvas Item Editor hierarchy
For anyone who wants change editor center by code: func set_editor_centor(var _center: Vector2):#set editor 2d center
var v = get_tree().edited_scene_root.get_viewport()
var t = v.global_canvas_transform
var s = t.get_scale()
var _center_offset = (v.size/s.x)/2#canvas editor center offset
_center = _center - _center_offset
var p = v.get_parent().get_parent()
for i in p.get_children():
print(i.get_class())
if i.get_class() == "CanvasItemEditorViewport":
for j in i.get_children():
if j.get_class() == "HScrollBar":
j.set_value(_center.x)
elif j.get_class() == "VScrollBar":
j.set_value(_center.y) |
See also godotengine/godot-proposals#1302. |
Reopening. #68696 was merged and changing Not sure how it should be solved. |
In the meantime, here's a more robust solution for setting both zoom and position: var editor = EditorInterface.get_base_control().find_child("@CanvasItemEditorViewport*", true, false)
var zoomer = editor.find_child("@EditorZoomWidget*", true, false)
zoomer.set_zoom(zoom)
zoomer.zoom_changed.emit(zoom)
var scroll = editor.find_child("@HScrollBar*", true, false)
scroll.value = pos.x
scroll = editor.find_child("@VScrollBar*", true, false)
scroll.value = pos.y |
Godot version
3.4.2 stable[45eaa2d] steam version
System information
windows 10
Issue description
When use set_global_canvas_transform() on editor viewport, the editor viewport transform immediately
But when any input(keyboard pressed, or mouse hovered on canvas editor), it will be reset as before. And the transform only change the item on canvas but not the hints( grids, axis..etc)
Steps to reproduce
Add a tool script then call
get_tree().edited_scene_root.get_viewport().set_global_canvas_transform()
Minimal reproduction project
EditorCanvasTransform.zip
The text was updated successfully, but these errors were encountered: