C# - The enemy doesn't stop after death

Godot Version 4.2.1

Question

It used to work, only recently noticed it was broken. After an enemy dies, I set it to “off” parameters, however now it doesn’t work

There are no scripts in the enemy itself, the EnemyManager is responsible for everything. However, after death works it becomes transparent and deleted, and everything else works like attack/hitbox, that is, after death invisible enemy can hit me.

EnemyManeger.cs (child node Enemy):

private async void OnDied()
        {
            SetProcess(false);
            SetPhysicsProcess(false);
            movementComponent.Speed = 0f;
            movementComponent.Direction = new Vector2(0,0);
            movementComponent.Move(entity);


            effectsComponent.Visible = false;

            shadowComponent.Visible = false;
            
            collisionShape2D.Disabled = true;

            hitboxComponent.Monitoring = false;
            hitboxComponent.Monitorable = false;

            attackComponent.Monitoring = false;
            attackComponent.Monitorable = false;

            animatedSprite2D.Modulate = new Color(1,1,1,0);
            gameManager.CurrentExperience += costResource.Experience;
            gameManager.CurrentMoney += costResource.Money;

            await ToSignal(damageIndicator.animationPlayer, AnimationPlayer.SignalName.AnimationFinished);
            entity.QueueFree();
        }

Anyway, added a Disable variable to each component that did the same thing as described in the code above and somehow it works. There’s logic in that it should work, but it’s not clear why it didn’t work…

You should use set_defered instead when disabling monitoring and monitorable.

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.