How to handle mouse event inside my Native GDModule?

Godot Version

4.2

Question

I have a class which adds some UI into Godot editor:

// my_module.h

class MyModuleDock : public VBoxContainer {
	GDCLASS(MyModuleDock, VBoxContainer);

protected:
	void _notification(int p_what); //Don't catch input events

public:
	MyModuleDock();
	~MyModuleDock();
	void _input(InputEvent *p_event);
};

And I want to handle mouse event inside the Editor (or 3D view only). How to implement it into MyModuleDock class without register_module_types of other class?

A few things come into mind.

  1. You need to declare the input function like this:
virtual void input(const Ref<InputEvent> &p_event) override;
  1. You need to enable input processing by calling:
set_process_input(true);

This could be done for example within the constructor MyModuleDock::MyModuleDock() {}.

2 Likes

It works! Thanks!

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