Getting "Parser Error: identifier not found" inconstantly on an identifier that is declared in base class

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By Just_a_Bee

This is a very confusing issue and I can’t even reproduce it outside my project.
I have a node of a class that exits as a scene on a tilemap. This node is of class Player. Player is derived from Pushable, which is derived from Actor. In Actor, I have the line @onready var level = get_parent()
This is then used anytime the node needs to interact with the TileMap level it exists in. Sometimes when I try to run my project it gives me the error: “Parser Error: Identifier not found: level” on line 16 of The code looks like this:

func _ready():
     level.player = self

This error occurs for any reference to variables declared in Actor.
If I change player to extend actor it fixes the issue, so it has something to do with extending a derived class of actor

I really have no idea why this happens, at first it was only in certain scenes, but now after changes that seem unrelated (storing levels in the level select as Packed Scenes instead of Tile Map Patterns) it’s happening in my main scene as well. If any more information about this is needed please ask!

What exactly do you want to do? Although the explanation of the whole project is too much, where do you get the error and what are you having trouble doing?

M.Kh | 2023-06-06 04:53

Thanks for your reply! I’m making a puzzle game.
Actor is the class for anything that exists on the tile map
Pushable is the class for Actors that get pushed when another actor moves into them
I want player to extend Pushable, but when I do that it sometimes (it was working when I first implemented it, and it seems almost random when the engine decides it doesn’t work anymore) the parser can’t find identifiers from Actor when I try to run it.
Originally this was only happening in exports of the game. Then it started happening when I would try to run a scene of a level, but not when running the level select. Now it’s happening when I run the level select as well.

Just_a_Bee | 2023-06-06 16:36

Hi, I have exactly the same issue :

I have this class hierarchy : A ← B ← C.
A has a member _member. When I use it in class C and launch the project, I get this error : Parser Error: Identifier not found: _member.
However, I have no troubles to use B members in C, or A members in B.

However, I can’t reproduce it in a simple project. Did you manage to do it since you posted ?
I noticed that the parser error happens depending on where I use the child class type C. I guess the engine is parsing it at a different time and this may or not produce the error.

I feel it’s a bug, we should definitively try to reproduce it and post it on github.

Elis4 | 2023-06-08 15:59

:bust_in_silhouette: Reply From: Elis4

Hi !

This is a bug. I was able to create a minimal reproduction project and thus post an issue on Github : Unexpected "Parser Error : Identifier not found" when using parent class member · Issue #78146 · godotengine/godot · GitHub

It’s being worked on by the community.

As a work-around before it’s fixed, you can try to change your autoloads order in Project Settings.