Skip to reading
3D Models & Video in GUIs

26. Start playback when the window opens

Edition 0.86.4.1 HF1

0.86.4.1 Hotfix 1 edition. Earlier lessons and screenshots retain their original version context; revised references and supplements describe the newer behavior.

Download PDFView PDF page

Autoplay is a construction/configuration request. It is not a new action that runs each time you call Show GUI. Hidden or already constructed elements make an explicit opening sequence easier to reason about.

Code example
extends "res://scripts/runtime/script_base.gd"
Code example
func run(_context: Dictionary = {}) -> Variant:
    await ShowGUI({"guiId": "video_lab"})
    var player := GetGUIElementProperty(
        "video_lab", "briefing_video", "video_player", null
    ) as VideoStreamPlayer
    if player == null or player.stream == null:
        return false
    player.paused = false
    player.play()
    return true

Assign this record to the Button or story event that opens the briefing. Keep Autoplay off when this script is responsible for starting it. Decide separately whether the opening HUD should be hidden.

If a particular GUI uses an opening transition, make sure the start time matches the intended presentation. Starting the movie immediately can advance frames while a long transition is still revealing the window.

1. Open the GUI for the first time and check the first visible frame.

2. Close it using the cleanup script.

3. Open it again and confirm the movie restarts because this script calls play.

4. Test a missing stream too; the GUI should still offer its poster/message and a way back.

For deliberate resume-on-open behavior, preserve the paused player and clear paused instead. That is a different design from stopping on close and restarting on open.

Page 36 of 45Permalink
Go to page