How to connect in c++ signal to method not using GD script

Godot Version

4.2.1

Question

Using c++ , i like to be able connect Timer timeout signal to my class method
Can’t find any documentation on how to do that .
In the Doc
At the the signal example uses GD script , i like to be able to call c++ function instated .

i did try like this :

void HealthManager::_ready() 
	{
	 

		pTimer = get_node<godot::Timer>("Timer");
		//pTimer->connect("timeout", godot::Callable(this,"test"));
		pTimer->connect("timeout", callable_mp(this, &HealthManager::test));
	}

	void HealthManager::test()
	{
		godot::UtilityFunctions::print("Test1");
	}

And the :test() never called

Thanks

1 Like

You need to add your callback method to the ClassDB in order for it to work.

ClassDB::bind_method(D_METHOD("test"),
&HealthManager::test);
1 Like

Can I call this method from the Editor Timer without initializing the Timer object in code?
Just wire the timeout callback in the editor, with no GDScript involvement.