Skip to content

Powerup: Don't access GameState in editor or before _ready#2359

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

Powerup: Don't access GameState in editor or before _ready#2359
manuq merged 1 commit into
mainfrom
wjt/powerup-don-t-access-gamestate-in-editor-or-before-ready

Conversation

@wjt

@wjt wjt commented Jun 12, 2026

Copy link
Copy Markdown
Member

Previously, during export:

SCRIPT ERROR: Invalid access to property or key 'quest' on a base object of type 'Node (game_state.gd)'.
          at: _update_ability_name (res://scenes/game_elements/props/powerup/components/powerup.gd:65)
          GDScript backtrace (most recent call first):
              [0] _update_ability_name (res://scenes/game_elements/props/powerup/components/powerup.gd:65)
              [1] _set_ability (res://scenes/game_elements/props/powerup/components/powerup.gd:43)
SCRIPT ERROR: Invalid assignment of property or key 'action' with value of type 'String' on a base object of type 'Nil'.
          at: _set_ability (res://scenes/game_elements/props/powerup/components/powerup.gd:44)
          GDScript backtrace (most recent call first):
              [0] _set_ability (res://scenes/game_elements/props/powerup/components/powerup.gd:44)

And when editing a scene that uses a powerup in the editor:

ERROR: res://scenes/game_elements/props/powerup/components/powerup.gd:65 - Invalid access to property or key 'quest' on a base object of type 'Node (game_state.gd)'.
ERROR: res://scenes/game_elements/props/powerup/components/powerup.gd:44 - Invalid assignment of property or key 'action' with value of type 'String' on a base object of type 'Nil'.
ERROR: res://scenes/game_elements/props/powerup/components/powerup.gd:65 - Invalid access to property or key 'quest' on a base object of type 'Node (game_state.gd)'.

powerup.gd is a @tool script (so that its appearance
can be updated based on the sprite_frames property, I guess) but
game_state.gd is not. But the Powerup.ability setter would
previously try to use properties of GameState unconditionally.

In _set_ability, skip _update_ability_name() in two cases:

  1. When running in the editor: GameState is not available here, and the
    ability_name property and the interact area's action description
    aren't used in the editor anyway.
  2. When not _ready(): When playing a specific scene with F6, GameState
    will not be _ready() at the point where the scene containing the
    powerup is added to the tree. So GameState.quest will be null and
    the powerup will always be named after the default abilities:
    incorrect if the quest eventually turns out to have custom names.

_set_ability is called again from _ready (in our standard pattern)
so this should cause no behaviour change in-game.

Helps #2353

Previously, during export:

    SCRIPT ERROR: Invalid access to property or key 'quest' on a base object of type 'Node (game_state.gd)'.
              at: _update_ability_name (res://scenes/game_elements/props/powerup/components/powerup.gd:65)
              GDScript backtrace (most recent call first):
                  [0] _update_ability_name (res://scenes/game_elements/props/powerup/components/powerup.gd:65)
                  [1] _set_ability (res://scenes/game_elements/props/powerup/components/powerup.gd:43)
    SCRIPT ERROR: Invalid assignment of property or key 'action' with value of type 'String' on a base object of type 'Nil'.
              at: _set_ability (res://scenes/game_elements/props/powerup/components/powerup.gd:44)
              GDScript backtrace (most recent call first):
                  [0] _set_ability (res://scenes/game_elements/props/powerup/components/powerup.gd:44)

`powerup.gd` is a `@tool` script (so that its appearance
can be updated based on the sprite_frames property, I guess) but
`game_state.gd` is not. But the `Powerup.ability` setter would
previously try to use properties of GameState unconditionally.

In `_set_ability`, skip `_update_ability_name()` in two cases:

1. When running in the editor: GameState is not available here, and the
   `ability_name` property and the interact area's action description
   aren't used in the editor anyway.
2. When not _ready(): When playing a specific scene with `F6`, GameState
   will not be _ready() at the point where the scene containing the
   powerup is added to the tree. So `GameState.quest` will be null and
   the powerup will always be named after the default abilities:
   incorrect if the quest eventually turns out to have custom names.

`_set_ability` is called again from `_ready` (in our standard pattern)
so this should cause no behaviour change in-game.

Helps #2353
@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/powerup-don-t-access-gamestate-in-editor-or-before-ready/.

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

Comment on lines +43 to +44
if not Engine.is_editor_hint() and is_node_ready():
_update_ability_name()

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Excellent, thanks for the detailed description of the problem.

@manuq manuq merged commit fc13f7a into main Jun 12, 2026
7 checks passed
@manuq manuq deleted the wjt/powerup-don-t-access-gamestate-in-editor-or-before-ready branch June 12, 2026 12:51
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