PlayerMode: Don't access GameState before _ready()#2360
Merged
Conversation
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.
|
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
approved these changes
Jun 12, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
When playing a scene directly (with F6) which uses PlayerMode with a
non-default mode, the scene would crash as follows:
The offending line of code is:
The issue is that
GameState.globalisnulluntilGameStatebecomesready. 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 accessGameStateif thePlayerModeis not ready.
GameStatewill become ready first, andPlayerMode._readycallsset_mode()again.