Issues with video files in Godot 4

Godot Version

4

Question

Hey everyone,

I’ve been working on a rhythm game, and I’ve run into a few issues with the code, particularly around handling backgrounds and resource switching. I’m using .ogv files for video backgrounds (Since godot only supports .ogv’s. I might just use webviews of youtube videos at this point), but the format is causing problems. Not only is it difficult to convert videos without losing quality, but the code doesn’t handle unsupported resource types gracefully, which could lead to crashes.

Another issue is the background fading logic. It works but feels overly coupled to specific nodes, making it harder to adapt or extend. The resizing logic for dynamic screen sizes is also repetitive, with similar calculations repeated for both images and video players, adding unnecessary complexity and increasing the risk of bugs down the line.

Lastly, I’d like the background to continue seamlessly between scenes, but I’m not sure how to implement that effectively in Godot while maintaining flexibility for other scene-specific logic. If anyone has tips on improving these areas or making the code more efficient, I’d love to hear your suggestions!

Here’s the github repo if you need it GitHub - zorauthedeveloper/Rhythm-Drive.

OGV is pretty rough to deal with but your video file is 300 kb/s, anything is going to look really bad at that bitrate. I’ve re-encoded a OGV of the same video at 3,000 kb/s, of which I’d recommend a higher bitrate for high quality mp4/mkv files and it looks fine in OGV with some artifacts.

Seems fine to me, it is coupled to specific nodes because you do want to fade out specific nodes, you’ll only have to swap between two backgrounds at a time right?

Resizing in code is totally unnecessary, using anchors correctly or container nodes will remove the entire function.

The only nodes that won’t be destroyed from change_scene_to_file are globally registered ones in the project settings, or added to get_tree().root in code. I’d recommend the former, register your “bg” scene as a global, you may need to give it a CanvasLayer as a root node, and remove it from other scenes.

This is my main issue. For some reason I keep getting errors when I try to set it as global, and I’m still not sure why.
Here are the errors
ERROR: Another resource is loaded from path 'res://background.tscn' (possible cyclic resource inclusion). ERROR: Failed to instantiate scene state of "res://background.tscn", node count is 0. Make sure the PackedScene resource is valid. ERROR: Failed to create an autoload, path is not pointing to a scene or a script: res://background.tscn. ERROR: editor/editor_autoload_settings.cpp:571 - Condition "!info->node" is true. Continuing.

Looking deeper it was already set to global, so you do not need to put BG in your game or main menu scene, it is automatically added via the Globals system.

Yep that fixed it. Just wondering but, what if I want a scene that does not have the BG. Is their a easy way to make sure that scene doesn’t have it? Just wondering. Also it’s kinda annoying not being able to see the BG in the scene editor. Is that just something that I’ll have to deal with or is their a way to see it.

For working with videos, I recommend using Godot 4.4.1 at least, which has several fixes for playing OGV. Video playback before 4.4 was broken. Godot 4.5 will have some more fixes and full features, like seek and speed control. Also, check Playing videos because there are important tips to get the best compression and quality.

And you can have videos playing in the editor using tool scripts (@tool), although using the expand property doesn’t seem to work that way, you’ll have to resize them with some other method.

1 Like