Hi,
I'm working with C# on "Your First 2D Game" tutorial and faced some issue.
Problem:
var player = GetNode<Player>("Player"); - I've got cast error or with some other syntax null value eventually.
System.InvalidCastException: 'Unable to cast object of type 'Godot.Area2D' to type 'Player'.'

What is different than in tutorial:
Folder structure. Currently it looks like:

  • GameFolder:
    --Main - all stuff for main scene and/or nodes
    --Player - all stuff for player scene and/or nodes

What I've tried so far:
Changing path to absolute path or aberrations based on NodePath and GetNode instructions, but failed. Tried to replace "Player" in brackets with "Player/Player" or "/root/Player/Player" or "C:/wholepath" or even some abomination like "../Player/Player". Of course you can see those were blind shots.
What I can achieve:
I can cast GetNode<Area2D>("Player") which of course rips off all custom methods and generally is not a case.
I can cast GetNode<Player>("Player/Player"); and get null value from that.
Screenshots:


For your Player script, are the file and class name both Player? Does it inherit from Area2D?

  • Pepi replied to this.

    award Yes, all is named Player with capital P and Player does inherit from Area2D. I can even use GetNode<Area2D>("Player") somehow, but than I cannot use Player object methods.