ManimCommunity / manim

A community-maintained Python framework for creating mathematical animations.
https://www.manim.community
MIT License
26.81k stars 1.84k forks source link

Unexpected Variable and Updater behaviour #3995

Closed Pasquale19 closed 3 weeks ago

Pasquale19 commented 3 weeks ago

Description of bug / unexpected behavior

While working with Variables and Updaters I discovered an behaviour I didn't expected.
First I added the updater to the Variable var1.add_updater(lambda mob: mob.tracker.set_value(self.renderer.time)). This is working. Then I added the updater directly to the tracker: var2.tracker.add_updater(lambda tracker: tracker.set_value(self.renderer.time)). I was wondering why this isn't working. Later I found out that I need to explicity add the tracker to the scene so the updater works, since the Variable doesn't add the internal tracker to scene automatically: self.add(var3.tracker)

Expected behavior

I thought the ValueTracker should be added to the submobjects of the Variable automatically.

How to reproduce the issue

Code for reproducing the problem ```py from manim import * class Updater_dt_Scene(Scene): def construct(self): #working var1=Variable(0,"var1") var1.add_updater(lambda mob: mob.tracker.set_value(self.renderer.time)) #not working var2=Variable(0,"var2") var2.tracker.add_updater(lambda tracker: tracker.set_value(self.renderer.time)) # working var3=Variable(0,"var3") var3.tracker.add_updater(lambda tracker: tracker.set_value(self.renderer.time)) self.add(var3.tracker) #important that updaters works vg=VGroup(var1,var2,var3).arrange(DOWN) self.add(vg) self.wait(4,frozen_frame=False) ```

Additional media files

Images/GIFs ![Updater_dt_Scene_ManimCE_v0 18 1](https://github.com/user-attachments/assets/a1beac89-019e-4f63-ade2-2809ae9dfc65)
uwezi commented 3 weeks ago

That you expected a different behavior does not automatically makes this into an issue. Manim only executes updaters of objects which are explicitly added to the scene - that's the normal behavior of updaters in Manim. If submobjects within other objects would be added to the scene themselves, that would make removing compound objects or transforming submobjects within other objects a recursive nightmare.

Pasquale19 commented 3 weeks ago

Ok thank you for your answer. Now I understand. Sorry for adding this as an issue.