Skip to content

Object::cast_to works incorrectly for GDExtension custom classes #995

@VanessB

Description

@VanessB

Copy of this issue#71332 from main repository, as it is related to GDExtension.

Issue description

Object::cast_to does not work properly in case of custom GDExtension classes. For example, a nullptr is NOT returned in some cases where an object can not be casted to the desired type:

(Let TestNode inherit from Node2D, some_node_2d be of type Node2D)

godot::Node::cast_to<TestNode>(some_node_2d) != nullptr;  // true, must be false, as Node2D can not be casted to TestNode.

From my experience, it seems that cast_to works with custom classes as if they are their base classes, as (in this example) I can cast all the classes inherited from Node2D to TestNode, and can not cast any other type (see steps to reproduce and reproduction project).

The GDScript, although, works fine with casting of custom classes, see example. C++ code for casting in-engine types also seems to work fine.

Steps to reproduce and example project with GDExtension source code can be seen here (issue#71332)

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugThis has been identified as a bug

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions