Commit fc13f7a
authored
Powerup: Don't access GameState in editor or before _ready (#2359)
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 #23531 parent c6b6a43 commit fc13f7a
1 file changed
Lines changed: 3 additions & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
40 | 40 | | |
41 | 41 | | |
42 | 42 | | |
43 | | - | |
44 | | - | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
45 | 46 | | |
46 | 47 | | |
47 | 48 | | |
| |||
0 commit comments