The patent application shall essentially be filed before any publication (lecture, article, etc.) since otherwise the invention would be disclosed to the general public and no longer new. In Germany and Europe publication is understood as meaning verbal and written communication or use of the invention in such a way that the essence of the invention can be registered.
An application shall be recommended in good time, since the invention must be new around the world. Researcher groups often work globally on similar issues. Another person may have the same inventive concept and be first to apply for it as a patent. And then you will come away empty-handed.
If publication is planned, revealing the content of the invention, this shall be notified to the university in good time (usually two months in advance), preferably in conjunction with the invention disclosure.