ManimCommunity / ManimCommunity/manim

Lagging animations with updaters and self.add

Open
#1,648 4 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

help wanted issue:bug
Dominant language
Python
Stars
40.9k
Forks
3.1k
Avg merge
3d 12h
Merged PRs (30d)
25

Description

## 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

```py
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

```py
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

https://user-images.githubusercontent.com/52650214/120992430-e36a4300-c782-11eb-80e4-d228dae55858.mp4

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by running the two provided Test(Scene) reproductions, comparing self.add(rect) with Create(rect) or FadeIn(rect) while the ValueTracker and mobject updaters run. Trace the scene behavior around repeated addition and updater execution. Done means the two cases no longer produce different lag, or the project clearly warns when self.add is unsuitable for objects with updaters.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
computer-graphics
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.