Godot Version
4.2Question
Simple question. Is it possible to see the global position coordinates of a node inside the inspector? Thx!
Simple question. Is it possible to see the global position coordinates of a node inside the inspector? Thx!
EDIT: My bad, I only noticed the 2D tag after I responded.
I am not 100% sure, because I work with 3D, but maybe Top Level under CanvasItem will make sure that the position is global? Again, not totally sure but I already responded and feel I should at least try
Below is for 3D
If you enable Top Level, the transform shown in the inspector will be Global Position
doesn’t this also modify the node behaviour in some way? I would just like to read the global coordinates
It’s not shown in the inspector, you would have to print(global_position)
or add a label for debugging
or make easy plug-in for that
Tutorial is for GDScript and C#
it would change the behavior, but depending on what you’re doing it might not matter. The other responses are good responses.
what do you mean by “adding a label”?
i dont know how to do that
Just a Node type for displaying text, under a CanvasLayer might be better. Toss this script on it
extends Label
@export var target: Node2D
func _process(_delta: float) -> void:
text = "%d, %d" % [target.position.x, target.position.y]
I did Plug-in Plugin .
in your project you needed extract zip.
folders should look like “res://addons/GlobalPosition2DGS”
in project Settings you go plugins and enable
now if editor inspector in all Nodes 2D next to local position you should have
if link in future will be down there code:
@tool
extends GridContainer
@export var _line_editX: LineEdit
@export var _line_editY: LineEdit
var object : Node2D
func _set_object(new_object : Node2D) -> void:
object = new_object
func _ready() -> void:
_line_editX.text_submitted.connect(_edit_x)
_line_editY.text_submitted.connect(_edit_y)
func _process(delta: float) -> void:
if(!_line_editX.has_focus()):
_line_editX.text = str(object.global_position.x)
if(!_line_editY.has_focus()):
_line_editY.text = str(object.global_position.y)
func _edit_x(new_x : String) -> void:
if(new_x.is_valid_float()):
object.global_position = Vector2(new_x.to_float(),object.global_position.y)
return
_line_editX.text = str(object.global_position.x)
func _edit_y(new_y : String) -> void:
if(new_y.is_valid_float()):
object.global_position = Vector2(object.global_position.y,new_y.to_float())
return
_line_editY.text = str(object.global_position.y)
@tool
extends EditorInspectorPlugin
func _can_handle(object: Object) -> bool:
if(object is Node2D):
return true
return false
func _parse_property(object: Object, type: Variant.Type, name: String, hint_type: PropertyHint, hint_string: String, usage_flags: int, wide: bool) -> bool:
if(name == "position"):
var _custon_control := preload("res://addons/GlobalPosition2DGS/GlobalPosition.tscn").instantiate()
add_custom_control(_custon_control)
if(_custon_control.has_method("_set_object")):
_custon_control._set_object(object)
return false
@tool
extends EditorPlugin
var plugin
func _enter_tree() -> void:
plugin = preload("res://addons/GlobalPosition2DGS/global_position_inspector_plugin.gd").new()
add_inspector_plugin(plugin)
func _exit_tree() -> void:
remove_inspector_plugin(plugin)
[plugin]
name="GlobalPosition2D with GDScript"
description="This plugin adds the global position to the inspector for all Node2D nodes."
author="Moreus"
version="0.1"
script="global_position_plugin_2d.gd"
This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.