How can i update a List add/remove items inside the Update function ?

using System.Collections;
using System.Collections.Generic;
using System.Linq;
using UnityEngine;
using UnityEngine.Events;

[ExecuteInEditMode]
public class AnimationCamera : MonoBehaviour
{
    public string test;
    public Camera animationCamera;
    public Camera mainCamera;
    private Animator _anim;
    public UnityEvent UpdateEvent;
    public List<AnimationClip> animations = new List<AnimationClip>();

    private void Start()
    {
        animationCamera.enabled = false;
        mainCamera.enabled = true;
        _anim = GetComponent<Animator>();
    }


    private void Update()
    {
        if (_anim == null)
            _anim = GetComponent<Animator>();

        foreach (AnimationClip ac in _anim.runtimeAnimatorController.animationClips)
        {
            if (!animations.Contains(ac))
            {
                animations.Add(ac);
            }
        }
    }
}

In this script i add item/s to the List according to change i’m doing in the Animator window in the editor.
If i add more animation clips to the Animator window it will add them to the animations List.

But now i want also to check in a case i removed animation from the Animator window how can i update the animations list by removing the item/s i removed from the Animator window ?
Now i’m doing only a check in case i need to add a new item/s but i need to check also removing.

What is the condition for removing from the list?

When in the Animator window when i remove the animation clip state then update the list in the script. Or update the list in the inspector but the condition is if i added a new animation clip to the animator window and it’s adding it to the list when i remove from the animator window remove it also from the list in the update function.

Can you not just reverse the process by adding another loop or does that throw an error?

        foreach (AnimationClip ac in animations)
        {
            if (!_anim.runtimeAnimatorController.animationClips.Contains(ac))
            {
                animations.Remove(ac);
            }
        }

You don’t want to do that in a foreach because now you’re modifying an enumerable while you’re enumerating it. Using a regular for loop and counting backwards from the last item would work though.

sounds alot like you’re simply deep copying the animationClips array from the RuntimeAnimatorController. any reason why you can’t just reference the array directly?