Accro
February 16, 2024, 12:24pm
1
Godot Version
Godot 4.0 stable
Question
I wanted to see what instance of the node the script is attached to so I tried to use get_tree().get_item_at_position() but it says “Invalid call. Nonexistent function ‘get_item_at_position’ in base ‘SceneTree’.” Does the function not exist or what?
This is my code:
extends Area2D
var Bakery_path : String = ""
func _on_area_entered(area):
if(area.is_in_group("Player")):
var Node_instance = get_tree().get_item_at_position(position_x_y.position_x)
You are thinking about the GUI node Tree
, the get_tree
method returns SceneTree
, which is different
Accro
February 16, 2024, 2:10pm
3
Can u give me the function then?
Under the assumption that your scene tree looks like this:
then you can use the following in order to get the tree item within the tree node:
extends Area2D
var Bakery_path : String = ""
func _on_area_entered(area):
if(area.is_in_group("Player")):
var tree_node: Tree = $Tree
var Node_instance = tree_node.get_item_at_position(Vector2(10, 10))
2 Likes
There is no function to find a node at a position in the scene, generally, it depends on what you are actually looking for
Accro
February 16, 2024, 3:53pm
6
It says node not found when i give the right node
Please provide more info about how your scene tree is set up and what you want to achieve.
2 Likes
Accro
February 16, 2024, 4:05pm
8
I want to name of the node instance i need to work with.
Scene tree is:
Then that doesn’t work at all, this method is specific to Tree
, there’s no general method for this
1 Like
Accro
February 16, 2024, 5:57pm
10
U said “: Tree” how would that work if it were say CharecterBody2D or Staticbody2D. What I mean is what node would have a type of “Tree”.
It won’t work? It only works with Tree
, not with those types
You can’t do what you are wanting to do with this, there is no way to find a node at a position like this
Accro
February 16, 2024, 6:04pm
12
Tysm
For letting me know.
Ill try to find a work around.
1 Like