All Questions

Community

Juan Uys

Please clarify adding StatusEffectContainer to player + enemy instead of Battler.tscn

Here's my transcript from Discord:


hey folks, quick question about https://gdquest.mavenseed.com/lessons/applying-status-effects In Battler.gd the _status_effect_container is null when the time_scale is set
[22:32]
I checked the spelling, and even let code-complete find the correct node here: onready var _status_effect_container: StatusEffectContainer = $StatusEffectContainer
[22:32]
I added a _ready() in the StatusEffectContainer script, with a print, but it doesn't seem to be called
[22:33]
I tried restarting Godot too
[22:37]
hmm, ok - my Battler "implementation" doesn't seem to have properly inherited from Battler.tscn, so it's missing the new StatusEffectContainer node

opyateToday at 22:50

Fixed now. I'll dig through the previous chapters to see if there was something unclear about "new inherited scene" when creating characters

opyateToday at 22:58

found it: https://gdquest.mavenseed.com/lessons/designing-base-animations section: Creating derived battler scenes
You could use the scene inheritance feature in Godot. I recommend to avoid it... <snip> That’s why, instead, I recommend creating new scenes, which is what we’ll do here.
[22:58]
so, the subsequent addition of StatusEffectContainer to Battler.tscn wasn't propagated to the player + enemy, because those were new and not inherited
[22:59]
What is a good solution here? Just create the StatusEffectContainer on both player + enemy? (perhaps the tut should reflect this)
  • Nathan Lovato replied

    As I answered on Discord, you can either:

    • Add an instance of the node in each battler scene.
    • Use scene inheritance for all battlers (I don't like it much in the feature's current state but it's an option)
    • Create a new StatusEffectContainer from code (and remove any existing instance from a battler scene).

    Here's how you'd go about creating it from code.

    var _status_effect_container := StatusEffectContainer.new()
    func _ready() -> void:
        add_child(_status_effect_container)

    Thanks for pointing this out, I took a note to update the corresponding lesson(s)