1

I run the script

func search():
    var pl = get_parent().get_parent().get_player()

and I get the error Non-existent function 'get_player' in the base 'Viewport'.

what to do?

I have to get from the parent node

func get_player():
return $Player

but an error comes out Invalid call. Nonexistent function 'get_player' in base 'Viewport'.

eglease
  • 2,445
  • 11
  • 18
  • 28
  • Are you sure you want the parent of the parent (`get_parent().get_parent()`)? How does your scene tree look like? How are the `Node`s with these scripts attached positioned relative to each other? – Theraot Jun 29 '23 at 22:44

1 Answers1

0

If you don't know what your parent nodes are,do a print(get_parent().name) that way you will get to the node you suppose.

If your parent node has a child node "player" do: get_parent().get_parent().get_node("player")

Would be helpful if you would post a picture of your scene,if you want an accurate answer

Asavel
  • 1
  • 1