-
-
Notifications
You must be signed in to change notification settings - Fork 19.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add PluginUITexture
import option for images
#36417
Add PluginUITexture
import option for images
#36417
Conversation
to be honest, Its probably better to just make sure textures are imported before the plugin is loaded. |
4dc5718
to
31e6e1a
Compare
PluginUITexture
import option for images
31e6e1a
to
92a927c
Compare
That may not be easy in every situation. For instance, if some script in the plugin is loaded as a singleton that preloads some scene needing a texture for UI. I think this change adds a lot of benefit at a very little code cost. When you see it running and you can use textures without importing them it looks super clean. For plugins containing no assets, those that have only an editor side, this makes them plug & play. |
This is why the editor has code to register plugins, you can put your singleton code in there. IMO this is a problem with a badly written plugin, more than a required feature. I am against adding this kind f hack. |
I think its probably easier to do have a function that does a yield until the import process is complete, so you can do whathever you want there. |
think about it, if we start adding this sort of hacks for this, then many other users will start asking for hacks f or other types of resources. Lets find a proper way to do it and document it. |
Maybe it's unrelated here, but as it is now, the first time a plugin loads it will fail to load textures. It has to be restarted, because it seems like the import and the subsequent file it creates happens after the registration of the plugin. I get this all the time when cloning my repositories. The first run spews errors. This is with a basic plugin that is simply using If a fix is to be had, I would also prefer it to just work without any special additional steps, like configuring dozens of texture imports with clicking and typing about the UI. |
Maybe in a future I'll come back with something different, but in the meantime I'm just closing this PR as not of enough general interest. |
FYI: Thanks to @avencherus pointing out #39313 (comment) which suggests a potential workaround for at least some cases (specifically using a texture atlas but maybe even image texture resource might be sufficient). TL;DR: Editor plugins shouldn't attempt to use the resource system during initialization despite documentation stating otherwise. Suggested workarounds:
Additional contextSome of this is already covered in my existing #17483 (comment) but here's some extra specifics... The code around this PR is a useful pointer to the underlying issue. Specifically, the code here which enables the plugins...: Lines 404 to 416 in 02f7908
...occurs before this comment (which appears in a number of places): Line 430 in 02f7908
Thus any plugin initialization code cannot rely on the resource system or it will break on the first load of a project. (Aside: I vaguely seem to recall there's a related issue I noticed with first import/loads from the Project Manager or Asset Library templates due to the same issue?) Waiting for resource reimportThe "waiting" *cough* mentioned in the code comment above is related to the state of these...: Lines 390 to 392 in 02f7908
...which affect the operation of the following methods (I don't remember the full details but I think there's a Lines 675 to 692 in 7f67674
Lines 645 to 673 in 7f67674
So, basically, if a plugin relies on the resource loading system (during plugin initialisation, I guess) it'll be broken on first load because the resource "reimport" (i.e. first import) won't have happened. Given that the current custom plugin documentation advises to use When should editor plugins first attempt to use the resource system?As I think on it, maybe part of the issue is that this advice in the documentation is incorrect when it comes to editor plugin initialization:
If first reimport doesn't happen until after plugin initialization then Obviously the resources need to get reimported before e.g. a dialog is first displayed, so any resource-related initialization should occur in a hook that's called after reimport completes. A complication originating from per-project plugins?Actually, that makes me think this is somewhat related to a potential design/implementation issue due to conflating the editor scene tree with the project scene tree--since addons are per-project not editor. An existing solution already applied elsewhereWhile re-researching all this I discovered 9131f70 which (maybe unintentionally?) fixes the equivalent issue for custom class icons by changing from using Lines 3694 to 3697 in 4689ece
to using Line 3644 in 9131f70
Which obviously bypasses the delayed first reimport entirely. But An additional import related wrinkle...I've also just realised that there's any additional issue which I mentioned in my earlier comment that tried to go down the
Inconclusion...So, depending on where one sits, this could be an engine bug, a design bug or a documentation bug...or some combination of all three. :) Edit: Previous issues semi-related to the issue of timing of resource imports: { This probably would've been better in #17483 so I'll at least put the TL;DR: there too. } |
When you write a plugin requiring some textures for its in-editor UI, you face the problem that they need to be imported. That's a problem especially if your plugin needs to be able to load them from the very beginning (because of preloads or because it needs to display some UI as soon as it's activated).
Normally, textures in Godot are imported so they are converted to proper formats depending on the import kind and settings, and that's good. However, in this scenario there's no ambiguity: you need to plug some textures into some
Control
s and you just need them to work.To meet that need, this PR adds a new import mode for images:
PluginUITexture
. What it does is importing the image as anImageTexture
with sensible flags for UI use (filter and mip-maps). This mode will have the original image loaded instead of any import "artifact" that is normally generated by other modes. For that, this mode is flagged as dummy.(The mode could have been named
ImageTexture
, but by giving it the name ofPluginUITexture
it's only reasonable use case is made explicit and confusion among the other import modes is avoided.)Finally, it's only enabled in tools builds. If a texture imported this way is attempted to be loaded in an exported game, a no-loader-found-for-this-resource error will be thrown.
This code is generously donated by IMVU.