Skip to content

Not declare _bind_methods() may be cause not call "_ready()" #1430

Description

@pupil1337

Godot version

4.3.dev(e5b4ef8)

godot-cpp version

4.3.dev(b021245)

System information

win11

Issue description

This may be a problem, and I'm not sure. For safety reasons, I reported it.

issue:

When Base class not declare _ready(), and Derive class declare _ready() but not declare _bind_methods(), the virtual func _ready() in Derive class will not called.

// base.h
class Base : public Node {
	GDCLASS(Base, Node)

protected:
	static void _bind_methods() {}
};
// derive.h
class Derive : public Base {
	GDCLASS(Derive, Base)

public:
	virtual void _ready() override {
		Base::_ready();

		UtilityFunctions::print("Derive::_ready");
	}
};

register Base and Derive, and use Derive as root node in engine, run the game:
Derive will not call _ready()

Causes:
// wrapped.hpp
static void initialize_class() {
	static bool initialized = false;
	if (initialized) {
		return;
	}
	m_inherits::initialize_class(); 
	if (m_class::_get_bind_methods() != m_inherits::_get_bind_methods()) { // derive class not declare _bind_methods() cause issue
		_bind_methods();
		m_inherits::register_virtuals<m_class, m_inherits>(); // register virtual (_ready,_process,...) in this line
	}
	initialized = true;
}

Steps to reproduce

Look Issue description.

Minimal reproduction project

N/A

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugThis has been identified as a bug

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions