lawnjelly / smoothing-addon

Fixed timestep interpolation gdscript addon for Godot Engine (version 3.2 or later)
MIT License
510 stars 29 forks source link

Attaching Control under Smoothing2D causes assert error: _SetProcessing(): Condition "!viewport" is true on set_as_top_level #32

Closed hsandt closed 1 year ago

hsandt commented 1 year ago

I know it's not common to attach a Control of a PhysicsBody2D, but I have a local HUD displaying life gauge near attached to my CharacterBody2D so it's convenient, and I need to smooth it or it will jitter relatively to my smoother character sprite.

(usually I'd use a Canvas Layer and manually move the gauge to match character, but it's more complex)

When you do so, you get a double assert error on start: _SetProcessing(): Condition "!viewport" is true on set_as_top_level:

Godot code:

func _SetProcessing():
    var bEnable = _TestFlags(SF_ENABLED)
    if _TestFlags(SF_INVISIBLE):
        bEnable = false

    set_process(bEnable)
    set_physics_process(bEnable)

    set_as_top_level(_TestFlags(SF_GLOBAL_OUT))  # here

Callstack:

E 0:00:01:0024 smoothing_2d.gd:110 @ _SetProcessing(): Condition "!viewport" is true. <C++ Source> scene/gui/control.cpp:2984 @ _notification()

smoothing_2d.gd:110 @ _SetProcessing() smoothing_2d.gd:57 @ @flags_setter() smoothing_2d.gd:234 @ _ClearFlags() smoothing_2d.gd:245 @ _ChangeFlags() smoothing_2d.gd:121 @ _notification()

(this shows twice)

However, the Control is still smoothed correctly, although set_as_top_level failed, apparently because it's called again later.

lawnjelly commented 1 year ago

Could be fixed by #39, #40 , but will wait to here from OP before closing.

hsandt commented 1 year ago

Indeed, error didn't appear as I was detaching Smoothing Node and reattaching it to an external parent node already in v1.0.3, but I also tested v1.2.1 disabling legacy toplevel and using global out with no Smoothing Node detachment at all, and it also works without error.