How to move Animation Clips into Animator Controller?

How can I move my own animation clips into an animation controller so it is a child in the project hierarchy. See pic below. I want them to be children of the controller so it is easier to maintain the project structure and know which clip belongs to which controller e.g. here all the new clips belong to More Button Controller.
folder-hierarchy

I’ve tried what is suggested here. It doesn’t work with existing clips. It throws an error saying ‘Clip already exists’.

I also tried removing and adding it and it does show up correctly in hierarchy but it also keeps the old copy. So now there are two items in the project window.

AssetDatabase.RemoveObjectFromAsset(animationClip);
AssetDatabase.AddObjectToAsset(animationClip, animatorController);

I’ve also tried AssetDatabase.MoveAsset where new location is AnimationController/ClipName. That doesn’t work either; it says ‘Cannot move.’

Is there no way to move existing clips to animator controller?

I was able to finally do this by creating a copy and then moving that into the object. It however, does not update it’s references. So you’ll have to manually replace the old ones. So it is best to do this in start.

NOTE: once you add it to asset I was not able to find a way to remove it! So create backup/VC.

    /// <summary>
	/// Moves existing animation clips to be part of animator controller.
	/// It does this by creating a copy and then adding a copy. It has option to delete the old copy.
	/// </summary>
	/// <param name="animationClip"></param>
	private void CopyExistingClip(AnimationClip animationClip)
	{
		var newCopy = Object.Instantiate(animationClip) as AnimationClip;
		newCopy.name = animationClip.name;

		AddClipToAnimatorController(newCopy);
		if (deleteOldCopies)
		{
			AssetDatabase.MoveAssetToTrash(AssetDatabase.GetAssetPath(animationClip));
		}
	}

	/// <summary>
	/// Creates a new clip and adds it to the animator controller.
	/// </summary>
	/// <param name="clipName"></param>
	private void CreateNewAnimationClip(string clipName)
	{
		var newClip = new AnimationClip {name = clipName};
		AddClipToAnimatorController(newClip);
		
	}

	/// <summary>
	/// Add the clip to animator controller and re-imports
	/// </summary>
	/// <param name="animationClip"></param>
	private void AddClipToAnimatorController(AnimationClip animationClip)
	{
		AssetDatabase.AddObjectToAsset(animationClip, animatorController);
		AssetDatabase.ImportAsset(AssetDatabase.GetAssetPath(animationClip));
	}

There is a easier way of moving an animation clip to a new controller.

  1. Create the new Controller
  2. In the Animator window, add a new empty state
  3. Select the created state and update the motion parameter (in the inspector window) with the old animation clip
  4. You will need to manually update the animation clip references. In the Hierarchy window, select the object containing the new controller. In the Animation window, select the clip and then click twice (not double click) in each of the missing references text. Update the text to the new hierarchy structure.

Hope it helps!