Repository: ManimCommunity/manim
File: manim/scene/scene.py (Python)

Code before:
                    unpacked = self.recursively_unpack_animation_groups(sub)
                    unpacked_mobjects.extend(unpacked)
            else:
                unpacked_mobjects.append(anim.mobject)
        return unpacked_mobjects

    def get_moving_mobjects(self, *animations: Animation) -> list[Mobject]:
        """
        Gets all moving mobjects in the passed animation(s).

        Parameters
        ----------
        *animations
            The animations to check for moving mobjects.

        Returns
        ------
        list
            The list of mobjects that could be moving in
            the Animation(s)
        """
        # Go through mobjects from start to end, and
        # as soon as there's one that needs updating of
        # some kind per frame, return the list from that
        # point forward.
        animation_mobjects = self.recursively_unpack_animation_groups(*animations)
        mobjects = self.get_mobject_family_members()
        for i, mob in enumerate(mobjects):
            update_possibilities = [
                mob in animation_mobjects,
                len(mob.get_family_updaters()) > 0,
                mob in self.foreground_mobjects,
            ]
            if any(update_possibilities):
                return mobjects[i:]
        return []

    def get_moving_and_static_mobjects(
        self, animations: Iterable[Animation]
    ) -> tuple[list[Mobject], list[Mobject]]:
        all_mobjects = list_update(self.mobjects, self.foreground_mobjects)
        all_mobject_families = extract_mobject_family_members(
            all_mobjects,
            use_z_index=self.renderer.camera.use_z_index,
            only_those_with_points=True,
        )
        moving_mobjects = self.get_moving_mobjects(*animations)
        all_moving_mobject_families = extract_mobject_family_members(
            moving_mobjects,
            use_z_index=self.renderer.camera.use_z_index,
        )

Review comment (suggestion):
If it works, I'd prefer a simpler solution not requiring a new method; something along the lines of the suggestion from my previous review:


```suggestion
        animation_mobjects = []
        for anim in animations:
            animation_mobject.extend(anim.mob.get_family())
```

Code after:
        def _collect_animation_mobjects(
            nested_animations: Iterable[Animation],
        ) -> list[Mobject | OpenGLMobject]:
            animation_mobjects: list[Mobject | OpenGLMobject] = []
            for anim in nested_animations:
                if isinstance(anim, AnimationGroup):
                    animation_mobjects.extend(
                        _collect_animation_mobjects(anim.animations),
                    )
                else:
                    animation_mobjects.extend(anim.mobject.get_family())
            return animation_mobjects

        animation_mobjects = _collect_animation_mobjects(animations)

        mobjects = self.get_mobject_family_members()
        for i, mob in enumerate(mobjects):
            update_possibilities = [
                mob in animation_mobjects,
                len(mob.get_family_updaters()) > 0,
                mob in self.foreground_mobjects,
            ]
            if any(update_possibilities):
                return mobjects[i:]
        return []

    def get_moving_and_static_mobjects(
        self, animations: Iterable[Animation]
    ) -> tuple[list[Mobject], list[Mobject]]:
        all_mobjects = list_update(self.mobjects, self.foreground_mobjects)
        all_mobject_families = extract_mobject_family_members(
            all_mobjects,
            use_z_index=self.renderer.camera.use_z_index,
            only_those_with_points=True,
        )
        moving_mobjects = self.get_moving_mobjects(*animations)
        all_moving_mobject_families = extract_mobject_family_members(
            moving_mobjects,
            use_z_index=self.renderer.camera.use_z_index,
        )
        static_mobjects = list_difference_update(
            all_mobject_families,
            all_moving_mobject_families,
        )
        return all_moving_mobject_families, static_mobjects

    def compile_animations(
        self,
        *args: Animation | Mobject | _AnimationBuilder,
        **kwargs: Any,
    ) -> list[Animation]: