Skip to content

PlayerMode: Don't access GameState before _ready()#2360

Merged
manuq merged 1 commit into
mainfrom
wjt/playermode-don-t-access-gamestate-before-ready
Jun 12, 2026
Merged

PlayerMode: Don't access GameState before _ready()#2360
manuq merged 1 commit into
mainfrom
wjt/playermode-don-t-access-gamestate-before-ready

Conversation

@wjt

@wjt wjt commented Jun 12, 2026

Copy link
Copy Markdown
Member

When playing a scene directly (with F6) which uses PlayerMode with a
non-default mode, the scene would crash as follows:

SCRIPT ERROR: Invalid access to property or key 'player' on a base object of type 'Nil'.
    at: @player_getter (res://scenes/globals/game_state/game_state.gd:57)
    GDScript backtrace (most recent call first):
        [0] @player_getter (res://scenes/globals/game_state/game_state.gd:57)
        [1] set_mode (res://scenes/game_logic/player_mode.gd:30)

The offending line of code is:

return quest.player if quest else global.player

The issue is that GameState.global is null until GameState becomes
ready. And the scene tree is set up before sending the ready
notification. This is a regression from commit
515115d refactoring the game state.

In PlayerMode.set_mode(), don't access GameState if the PlayerMode
is not ready. GameState will become ready first, and
PlayerMode._ready calls set_mode() again.

When playing a scene directly (with F6) which uses PlayerMode with a
non-default mode, the scene would crash as follows:

    SCRIPT ERROR: Invalid access to property or key 'player' on a base object of type 'Nil'.
        at: @player_getter (res://scenes/globals/game_state/game_state.gd:57)
        GDScript backtrace (most recent call first):
            [0] @player_getter (res://scenes/globals/game_state/game_state.gd:57)
            [1] set_mode (res://scenes/game_logic/player_mode.gd:30)

The offending line of code is:

    return quest.player if quest else global.player

The issue is that `GameState.global` is `null` until `GameState` becomes
ready. And the scene tree is set up before sending the ready
notification. This is a regression from commit
515115d refactoring the game state.

In `PlayerMode.set_mode()`, don't access `GameState` if the `PlayerMode`
is not ready. `GameState` will become ready first, and
`PlayerMode._ready` calls `set_mode()` again.
@wjt wjt requested a review from a team as a code owner June 12, 2026 09:56
@github-actions

Copy link
Copy Markdown

Play this branch at https://play.threadbare.game/branches/endlessm/wjt/playermode-don-t-access-gamestate-before-ready/.

(This launches the game from the start, not directly at the change(s) in this pull request.)

@manuq manuq merged commit ba13b57 into main Jun 12, 2026
7 checks passed
@manuq manuq deleted the wjt/playermode-don-t-access-gamestate-before-ready branch June 12, 2026 12:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants