Game freezing for a sec when sprite with shader gets loaded

Godot Version

4.3

Question

My game freezes for a second when a sprite with a shader attached becomes visible for the first time since the game started.
How can I prevent this?
Thanks in advance!

You can force the shader compilation by displaying the material on a small object before starting the level while showing some kind of message like “Loading, please wait.” I describe something like this in my tutorial. It’s 3D, but the principle is the same.

It looks like it might be fixed for Godot 4.4. The github pull request this blog post talks about regarding pipeline compilation and ubershader is merged.

1 Like

Thank for the replies!
They both worked, but since I’m using godot 4.3 I’ll use the first one

They talk about the v4.4 enhancement shader optimization around the 7 minute mark and there is a catch. One has to put all the shader objects onto some nodes in the scene tree. I’m guessing you can do this programmatically and use hide() and show() as necessary. Kinda up a lot of front work depending but the results sounds worth it.

Still better then using a camera3d and going through each level to trigger the shader compilation.

It seems like this video is the only thing that talks about this caveat. I don’t see anything about it in the GitHub description. But maybe it’s also mentioned in the comments. One could just test the new dev version to evaluate what the workload would be.

1 Like

I’ll definitely try it!
Thanks a lot!

Here’s additional info, a chapter in the official docs for upcoming Godot 4.4: Reducing stutter from shader (pipeline) compilations.

Thanks! It was really helpful!