Great, this is all very helpful.
Excellent, this is another great debugging tool (which I had completely forgotten about because I’m almost certain they’re not supported in GDScript).
Very cool! That will help with the explanations I’m sure.
I’m pretty sure I see what’s going on in relation to the error message you gave here.
The idea behind the code that happens in IdleState.Ready()
is that it’s building a reference to the Player node, and it’s doing that using GetOwner()
. That call returns the root of the scene being operated in, and that’s a very important detail. If you look closely at your screenshots, you’ll see that one reason why your scene trees are different is because in the first screenshot (which is of your project), you’re looking at the Main scene, in which the Player is simply instantiated; in the second screenshot (which is of Luis’s project), he has the Player scene open, in which the Player is the root of the scene.
If you’re experienced with C#, I’m sure I don’t need to explain what typecasting is in general. The reason you’re getting this error is because the IdleState script is running in the Main scene, and therefore GetOwner()
returns Main, which is a Node3D that is not of class Player
(Godot can use class names as object datatypes. Luis talks about this briefly at around the 4m mark in this lecture). Because there is no native way to typecast an ordinary Node3D to this Player
datatype, the result is an unhandled type mismatch exception.
Because this lecture is all about migrating existing functionality out of Main and into Player, probably what’s happening is IdleState is running on both scenes and it’s failing on Main, where it isn’t meant to run anymore - keep in mind that both IdleState nodes would be running the same script! Being experienced with C#, I’m assuming you’re familiar with breakpoints too; try stepping through your code to see if this is the case, paying close attention to the script in which each sequential line of the control flow is in.
Either way, if you follow the lecture all the way through to completely finish the functionality migration procedure that Luis demonstrates, there’s actually a very good chance this problem will fix itself.
Someone else had an issue with this, and it is indeed a line that Luis writes himself; however, that’s actually all done in the next lecture. It starts at around 5:30, but I’d rewatch the whole thing anyway so you have the context behind it.