-
Notifications
You must be signed in to change notification settings - Fork 2.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Using Swap on two Mobjects in a group can cause self.remove to not work on that group #4210
Comments
The issue with this code is that the Example: class SwapTest(Scene):
def construct(self):
text_a = Text("A").move_to([1, 0, 0])
text_b = Text("B").move_to([2, 0, 0])
text_group = Group(*[text_a, text_b])
self.play(FadeIn(text_group))
self.play(Swap(text_a, text_b))
self.add(text_group)
self.remove(text_group)
self.wait(3) Why does Another Example where
|
Interesting. I'm still a bit confused by the behavior however. The group is displayed on screen after running
However, if we include I think this also raises a question about how |
This is actually the behavior of The same applies to class SwapTest4(Scene):
def construct(self):
text_a = Text("A").move_to([1, 0, 0])
text_b = Text("B").move_to([2, 0, 0])
text_group = Group(*[text_a, text_b])
self.play(FadeIn(text_group))
# At some point, you use FadeIn again, but now on the individual mobjects.
# self.remove(text_group) will have no effect after this.
self.play(FadeIn(text_a, text_b))
self.wait(1)
self.remove(text_group)
self.wait(1) Another approachI'm not sure whether However, you would need to pass in the group itself. |
I have submitted a pull request to address this issue: #4211. Now, Example: class SwapTest5(Scene):
def construct(self):
text_a = Text("A").move_to([1, 0, 0])
text_b = Text("B").move_to([2, 0, 0])
text_group = Group(*[text_a, text_b])
self.play(FadeIn(text_group))
self.play(Swap(text_group)) # now passing that group
self.remove(text_group) # it can be removed
self.wait(2) |
Great, thanks for the info and PR! I'm surprised to learn that groups can be removed from a scene as a side effect of so many actions. I think the practical solution for me will be to use I'm happy to consider the issue closed once the PR goes through. |
Glad to hear that! Yes, It seems that when we create a new group with the same members and add it to the scene, the scene automatically replaces the old group with the new one. Here’s an illustration: from manim import *
text_a = Text("A").move_to(LEFT)
text_b = Text("B").move_to(RIGHT)
# we create a group for those mobjects
group1 = Group(text_a, text_b)
# create a scene
scene = Scene()
scene.add(group1)
print(scene.mobjects) # only 1 mobject in the scene
print(group1 is scene.mobjects[0]) # True
# now we create a new group with the same members
group2 = Group(text_a, text_b)
scene.add(group2) # add new group to the scene
print(scene.mobjects) # it remains 1 mobject in the scene
print(group1 is scene.mobjects[0]) # False
print(group2 is scene.mobjects[0]) # True So, the scene does not store both groups but replaces the previous one. |
Description of bug / unexpected behavior
After using
Swap
on twoMobjects
in the sameGroup
, I have found that attempts to useself.remove
to remove theGroup
sometimes fail and theGroup
remains visibleExpected behavior
Running
self.remove
on aGroup
should cause thatGroup
to no longer be visible and precedingSwap
commands should not affect this.How to reproduce the issue
Code for reproducing the problem
Additional media files
SwapTest.mp4
When uncommenting the specified line, we see
self.remove(text_group)
working as expectedSwapTest.mp4
System specifications
System Details
python --version
) - Python 3.11.4pip list
):Additional comments
self.remove(*text_group)
(with the unpacking operator*
) works as expectedThe text was updated successfully, but these errors were encountered: