Out of nowhere, I get this error in my player.gd script which is attached to a Player CharacterBody2D scene. The Player scene shows up in the main game (which is a Node2D) as an instance along with instances of Node2D’s containing TileMapLayers and instances containing other CharacterBody2Ds.
I checked that all my scripts match all their node types.
I went back to the last working version and deleted the Player scene and script from the non-working project and copied in working versions of the scene and script, reloaded the project, and I still get the error.
My guess at this point is the engine messed up saving some obscure file while I was working on my latest version with spotty internet connect and now something somewhere is corrupted. My only solution at this point is to go back to my last working project and retype everything to get back to where I was. Super-frustrating.
Thanks for the advice. I tried it and it didn’t solve it. Maybe it’s just a bug that appears when the safe save isn’t successful when I’m working on my laptop on a project in the cloud with a spotty internet.
I was able to go back to a previously saved version and copy paste the Player, Location, NPC and World scripts from the non-working version into the old version and everything works.
That error usually means a scene file still has the script attached to a plain Node instead of the CharacterBody2D. When a save gets interrupted, a .tscn can end up with a node’s type reverted while the script stays on it. Copying scripts over won’t catch it because the problem is in the scene file, not the script.
Open the broken project’s player.tscn (and your main scene) in a text editor and look at the node lines. If you see type=“Node” where it should say type=“CharacterBody2D”, that’s the corruption. Fix the type by hand, save, reopen, and the error should be gone.
If it looks clean, can you paste the top of the .tscn here? The node and script lines would tell us a lot.
The player.tscn paste cut off right before the part we need. Everything you posted is the header and resource list, the node lines come after that. Can you paste a few more lines of player.tscn, specifically the first line starting with [node?
It should look something like this:
[node name=“Player” type=“CharacterBody2D”]
If it says type=“Node” or some other type instead, that’s the corruption I was talking about.
Also, can you paste the exact error message text? That could help narrow down whether it’s the script attachment or something else.
Sorry about that. Here’s most of it. The new working version and the buggy version look the same to my eyes, but perhaps this buggy version has the information you’re looking for.
That node line looks right, type=“CharacterBody2D” with the script on it, so now we know that at least.
Can you paste the exact error text from the Output or Debugger panel, including the file and line number if it has one? I’m not sure which error we’re chasing now.
Also does it show up the moment you open the project, or only when you run the game?
Change extends CharacterBody2D to extends Node, comment out rest of the code and add _ready() function that prints node’s path. This will identify node(s) the script is actually attached to.
You could possibly find it with a project wide text search. In your editor do a find in files across the whole project folder for player.gd, and again for its uid, uid://4a41rw88mmhy, since scenes can reference the script either way. Every .tscn that comes back is attaching that script somewhere.
Then in each hit, look at the [node ...] line directly above the script = line. You’re looking for one that says type="Node" instead of type="CharacterBody2D". If a scene got saved with the node type reverted while the script stayed on it, that’s what would throw this at run time.
If the search only ever turns up player.tscn and world.tscn, then I’d start looking at code instead, anything doing set_script() on a node you created yourself. That would produce the same message without any scene file being wrong.