24. Stop the movie when closing the GUI
Hiding the GUI did not stop the embedded player in this guide’s runtime test. Use an explicit close script when the movie and its audio should stop as the window closes:
extends "res://scripts/runtime/script_base.gd"func run(_context: Dictionary = {}) -> Variant:
var player := GetGUIElementProperty(
"video_lab", "briefing_video", "video_player", null
) as VideoStreamPlayer
if player != null:
player.stop()
player.paused = false
await HideGUI({"guiId": "video_lab"})
await ShowGUI({"guiId": "media_hud"})
return true1. Add your own Close Button, or assign this script to the existing GUI close element.
2. Use run-visual-script and the script’s ID as Click Target.
3. Play a clip and close the GUI while it is running.
4. Reopen it and check the behavior you intended: explicit restart, deliberate resume or an idle screen.
The null check still allows the GUI to close when a player or stream is unavailable. A broken video should not trap the user inside the window.
media_hud is the example’s small opening menu. Replace that ID with your own HUD or omit the ShowGUI line if your game does not need it.
