Description
Godot version
4.2
godot-cpp version
4.2
System information
Windows 10 and Linux Mint
Issue description
When creating custom UI elements we have the possibility to use ThemeDB::get_singleton()->get_default_theme()
to define the styling of the Control. However doing so significantly slows down the editor loading. Note that this is the loading time of the editor that gets way longer. Running the game/app works without any noticeable longer loading time.
That said, currently I'm calling a function from the constructor which creates the default theme styles/colors/constants... then assign them into the default theme object. I have a static flag that is set whenever this setup is completed for the first time so further instantiations of the Control don't create everything again. Just after that I call a function to cache those things into an internal struct (similarly to the core controls).
I originally wanted to build the styles and assign into the default theme from the _bind_methods()
function, however at that moment get_default_theme()
returns an invalid object.
I have attached a minimal custom Control to help test the slow down. In the code, however, I have added a third function to first initialize the theme cache. Indeed it leads to multiple creations of the default styles when multiple instances are created. However this is done so the function to assign things into the default theme can be commented out in order to compare the difference in the editor load time.
I also added several prints telling that something is being assigned into the default theme object. This is just to show that it does take some time between each theme->set_*()
call is finished.
I have noticed that the very first loading of the extension was OK, however subsequent attempts to load the project were as described, slow.
Steps to reproduce
- Compile the attached theme tester Control and create a project that uses it
- As described, the very first time the extension is loaded might not show any problem, however subsequent loading should be slower
- Comment out a line that is indicated within the constructor then build and test again. Commenting that line will not assign things into the default theme object, which should result in faster loading time of the editor