Invalid cast when using [Export]

Godot Version

4.2.2

Question

I’m getting “true” printed in the console with the following setup; meaning that the CharacterBody3D was never referenced correctly.

I have a player.tscn with a PlayerMovement script on the player.

public partial class PlayerMovement : Node
{
    [[Export] private CharacterBody3D _body;

    public void ApplyVelocity(Vector3 direction, double delta)
    {
        // Prints true
        GB.Print(_body == null);
    }
}

This is the PlayerMovement node setup, clearly referencing the body
PlayerMovement

I also have a main.tscn with the mentioned player.tscn as subscene. This is the main player node with a Player.cs attached to it.

extra ‘[’?
[Export] private CharacterBody3D _body;

Heyo, the issue was that my deriving class didn’t extend the deepest class that it was attached to. I wasn’t aware that in Godot attached scripts need to extend classes of the nodes they are attached to.

Thanks for the feedback

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.