-
-
Notifications
You must be signed in to change notification settings - Fork 3.3k
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
Clarify what an imported resource really is and how to load external files (png, jpg, ogg, wav...) #2148
Comments
Good one. This probably belongs in the "I/O" section of Tutorials. |
Updated the load an image example. |
Damn right. I also stepped into that hell of confusion and so I want to ping this issue (or just mark it as a reminder for myself). As discussed in the referenced issue of the godot repository there are currently a few file formats which can be loaded at runtime: By a combination of gdscript functions: Or by using a plugin: A simple page in the I/O section of the docs which sums this up and collects the mentioned code snippets that were posted in those related issues would be of great benefit. |
This comment was marked as off-topic.
This comment was marked as off-topic.
This does not work for me on Android
It does work fine on Windows though. Any help how to load external image data as a sprite texture on Android would be greatly appreciated! Edit: Ok so after a hole day of painful trail and error, I figured out I apparently I have to check "Media Content Control", "Read External Storage", "Write External Storage", and call
Any single one of those options won't do. |
Thank you for sharing, how would you load a wav file? |
As stated in my last comment you could use https://github.com/Gianclgar/GDScriptAudioImport. The code for loading a wav-file can be found on line 61. (But there are problems with specific files) |
@mrcdk thank you so much for this thread! I was just struggling with this over the last couple days... And I came across this Q&A page for the exact same issue, so I just submitted an answer that links back to this thread 😄 |
Another aspect to this which I don't think has been mentioned is when loading a texture for a sprite in a tool script (i.e. design time). If I add the texture via the editor or use load(), it links the texture file as an "ext_resource". However, if I use the code get_external_texture() as above, it adds the texture data directly to the tscn file, making for potentially very large files. |
Unfortunately my comment above is quite outdated. As I wanted to update my knowledge for Godot 4.x, I stumbled across two new methods coming with Godot 4.2 🎉:
For the sake of completeness (and because I wondered why it hadn't been linked yet), here's the supplemental proposal: |
Are there any alternative obj loaders? The one linked doesn't work without mtl. |
Hey @FrasherGray thanks to your comment I stumbled upon the docs page Runtime file loading and saving introduced by @Calinou in #8363 (and there is also a corresponding demo added in godotengine/godot-demo-projects#993). So there is actually a pretty current documentation about file loading and you should ignore old comments and scripts that were posted before. The question arises if this issue here is still relevant now that the page exist. It wasn't linked in the PR so I guess @Calinou wasn't aware of this discussion. Anyway regarding your question:
The issue talking about it not being able to do so seems to be quite old. Have you tested it yourself? The only alternative I see right now is using Godots ability of loading a GLTF file at runtime. So you could convert any obj-file into a glb-file first and then load those. There is still an open issue about it #6385 that you should read if you consider using this workaround. |
@pwab I got it to work by commenting out the entire "use-mtl" case where the issue was arising. Since I will always be assigning materials within the project and not with blender, it works fine for me. |
it's not the first time (and won't be the last) where an user tries to load an external file (a file that has not been imported) with
load()
orResourceLoader.load()
and gets confused because it doesn't load or it fails.We need to explain them that those functions only work with imported files and what they should do to load external files. I think we need to specify somewhere that imported resources aren't the same as files and how to load external files but I have no idea where.
I'll try to explain it and hope that someone can unmess the mess I write 😅
And some examples to load different files:
Load an ogg file:
Load a png file:
The text was updated successfully, but these errors were encountered: