godotengine / godot

Godot Engine – Multi-platform 2D and 3D game engine
https://godotengine.org
MIT License
91.52k stars 21.26k forks source link

Weird error "get_node" #34396

Open git2013vb opened 4 years ago

git2013vb commented 4 years ago

Godot version: 3.2 beta3 OS/device including version: win7-64 Issue description: I have this error :Error 15,1: The method "get_node" isn't declared in the current class. in this line: onready var pos_spawn_enemy_mid:Vector2 = $Ground/SpawnPivots/EnemyMid.position

in terminal i have this error:


* daemon not running; starting now at tcp:5037
erasing C:\Users\homev3\AppData\Roaming/Godot/projects/topdown-656ff94ce70ac8286e098a1814b517d0/filesystem_update4
SCRIPT ERROR: GDScript::reload: Parse Error: The method "get_node" isn't declared in the current class.
          At: res://src/maps/Map.gd:15
ERROR: reload: Method/Function Failed, returning: ERR_PARSE_ERROR
   At: modules/gdscript/gdscript.cpp:576
* daemon started successfully
Running: C:\Users\homev3\Desktop\Godot_v3.2-beta3_win64.exe --path c:/Users/homev3/Documents/GoDot/release/projects/topdown
007 --allow_focus_steal_pid 19708 --position 1920,0
Godot Engine v3.2.beta3.official - https://godotengine.org
OpenGL ES 3.0 Renderer: GeForce GT 650M/PCIe/SSE2

ERROR: debug_get_stack_level_instance: Condition ' _debug_parse_err_line >= 0 ' is true. returned: __null
   At: modules/gdscript/gdscript_editor.cpp:338

in debug dock I have this error:

E 0:00:00.745   debug_get_stack_level_instance: Condition ' _debug_parse_err_line >= 0 ' is true. returned: __null
  <C++ Source>  modules/gdscript/gdscript_editor.cpp:338 @ debug_get_stack_level_instance()

But I have no idea if is related

Steps to reproduce: I moved the $Ground Minimal reproduction project: NA

akien-mga commented 4 years ago

What class does Map.gd inherit from? get_node is a Node method. Most likely your class doesn't inherit Node or a derivate class.

@bojidar-bg @vnen Maybe we can make the error message clearer when $ is used in a non-Node class?

git2013vb commented 4 years ago

What class does Map.gd inherit from? get_node is a Node method. Most likely your class doesn't inherit Node or a derivate class.

@bojidar-bg @vnen Maybe we can make the error message clearer when $ is used in a non-Node class?

You right! I have nothing in first line but I had a extends Node2D before moving it

KoBeWi commented 4 years ago

From my experience, this usually happens when inherited script has an error, so it can't be properly loaded.

MJBrune commented 4 years ago

I'm getting this currently with an inheritance depth of 3. Does inheritance just start to break down after a certain depth?

MJBrune commented 4 years ago

restarting the editor immediately took care of it... 🤷‍♂️

dweremeichik commented 4 years ago

I just ran into the same issue. The class I was inheriting from was also called "Map" not sure if that has anything to do with it. As @MJBrune stated a restart of the editor did the trick.

PoisonousGame commented 3 years ago

restarting the editor immediately took care of it... 🤷‍♂️

It works!

graydwarf commented 3 years ago

I received this error when my inherited class (Unit.gd) wrongly called a method in the sub-class (Wolf.gd). I accidently put the function Death() in Wolf and then tried to call it from a function in Unit. Just a copy/paste issue but troubleshooting it was difficult because the error message (posted by op) doesn't help much.

Unit (extends KinematicBody2D) Wolf (extends Unit)

vnen commented 3 years ago

My guess is that what happens is that if your parent script has any error then the inheritance chain isn't detected, so the script doesn't know it's a Node. If you fix the parent script, then you have to re-parse the child one (by editing it, for instance) and that's why restarting the editor fix it.

The solution for this would be to add a clear message when the parent script is invalid for any reason. The editor should also re-parse scripts when they are selected, especially when there is any error.

AndreaTerenz commented 2 years ago

I am having the same error: the class in question in AmmoPickup and the inheritance "chain" is AmmoPickup -> BasePickup -> Interactable -> StaticBody, which is clearly a built-in, Node-derived type; also, all scripts have zero errors and are correctly loaded. But, since there's an error, any exported variable from any of those classes is hidden in the editor because "the scripts contains a mistake". Like @MJBrune said, restarting the editor usually fixes the problem, although it eventually comes back again. The whole thing does look like a bug

MJBrune commented 2 years ago

@AndreaTerenz if you take @vnen's theory then reparsing from the base to the top child class should result in a fix. Essentially just having all the scripts open in the chain I've found can help. Go to each of them. I have the same situation with my interactable class and since keeping it open in the editor I've not had this issue with any child.

AndreaTerenz commented 2 years ago

@MJBrune I tried that and it doesn't work. It's probably a bug in how the editor tries to climb up the hierarchy "ladder" to determine the methods and attributes of a class