Add Animation Clip to Animator Controller

I have a button (Unity UI) and I put the transition to Animation. Then a button appears to create a default controller and animator. It creates a controller with 4 Animation Clips inside of the controller (in Project View). And only one file is created on disk.

Now I would like to add custom Animations to the controller. Is there a way to add them under the controller (inside the same file) instead of an Animation Clip in a separate folder?

I tried to do it through code:

		AnimatorController controller = obj as AnimatorController;
		if (controller == null) return;

		AnimationClip m = new AnimationClip { name = "NewAnimation" };
		controller.AddMotion(m);

This adds a state to the controller with the animation. But the animation is never saved, not in the controller or in a separate file. And when reloading the project the animation is gone.

No, you always need an AnimationClip asset (on disk) to assign to the ‘clip’ field of the state.

unity ui code

        // Create the clip
        var clip = Animations.AnimatorController.AllocateAnimatorClip(name);
        AssetDatabase.AddObjectToAsset(clip, controller);

        // Create a state in the animatior controller for this clip
        var state = controller.AddMotion(clip);