Skip to content

Event Handler Lifetime: Documentation vs. Implementation #103

Description

@CodeAndWeb

The documentation at https://www.monogameextended.net/docs/features/2d-animations/animatedsprite/ states that event handlers must be unsubscribed to prevent them from accumulating and being executed multiple times.

However, the actual implementation creates a new AnimationController each time AnimatedSprite.SetAnimation() is called. This effectively discards all previously registered handlers, making manual unsubscription unnecessary.

It’s also unclear whether the “Persistent Event Handler Pattern” described on that page is applicable. Since SetAnimation() replaces the existing AnimationController, any previously attached handlers would no longer be invoked. (I haven’t verified this in practice, as the sample code provided on that page does not compile.)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions