Skip to content

Lagging animations with updaters and self.add #1648

@PhilippImhof

Description

@PhilippImhof

Description of bug / unexpected behavior

Animations behave differently depending on the way the mobject was added to the scene. If I use self.play(Create(mobj)) there is no lag, if I use self.add(mobj) the animation lags in certain cases.

Expected behavior

IMHO there should be no difference between the two cases. Also, if using self.add is discouraged for objects that have updaters, we might consider printing a warning.

How to reproduce the issue

See the following code:

Code running with no lagging
from manim import *

class Test(Scene):
    def construct(self):
        tracker = ValueTracker(-3)
        rect = Rectangle().set_x(tracker.get_value())
        label = Text("x")
        rect.add_updater(lambda m: m.set_x(tracker.get_value()))
        label.add_updater(lambda m: m.move_to(rect.get_center()))
        self.add(rect,label)
        self.play(tracker.animate.set_value(4))
        self.wait()
        self.play(FadeIn(rect))
        self.play(tracker.animate.set_value(-4))
        self.wait()
Lagging animation in the second part
from manim import *

class Test(Scene):
    def construct(self):
        tracker = ValueTracker(-3)
        rect = Rectangle().set_x(tracker.get_value())
        label = Text("x")
        rect.add_updater(lambda m: m.set_x(tracker.get_value()))
        label.add_updater(lambda m: m.move_to(rect.get_center()))
        self.add(rect,label)
        self.play(tracker.animate.set_value(4))
        self.wait()
        #self.play(FadeIn(rect))
        self.add(rect)
        self.play(tracker.animate.set_value(-4))
        self.wait()

Additional media files

Test.mp4

Metadata

Metadata

Assignees

No one assigned

    Labels

    help wantedWe would appreciate help on this issue/PRissue:bugSomething isn't working... For use in issues

    Type

    No type

    Projects

    Status

    🆕 New

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions