Animation clip created with script is empty

And so, I will try to briefly describe the problem.

Based on answer to this topic, I wrote the logic that creates animation from png files.

The problem is that when switching to Play Mode, Unity removes all sprites from the animation, making it (animation) empty.
Any ideas what this is related to?

[186353-изображение-2021-09-17-114727.png|186353]

I solved the problem.

Instead of pulling sprites from the system file, I took them from RAM, as a result of which there were no references for the animation to work.

Paste the code in case someone has the same problem.

foreach (var file in files) {
    sprites.Add(AssetDatabase.LoadAssetAtPath<Sprite>(file));
}