Add animation clip at runtime

I’ve read over many “answers” to the question, but none have worked for me thus far. So pardon the possible redundancy, and I appreciate any help that can be offered:

I’d like to take a specific set of animation-clips from the assets folder, imported automatically while importing an FBX, and assign them to a mesh at runtime(during the “Start” or “Awake” call in a script), to be triggered later via code. All this works, so far, as long as the clips are attached to the mesh in the editor BEFORE runtime. Though, ideally, I’d rather assign only specific clips at start/awake, than assign more animation clips than are needed(in the editor beforehand) for a specific scenario(say for a specific weapon that is equipped on a character, calling for only a specific set of animations).

This is key: these animations would ideally NOT be assigned specifically beforehand in the editor. I have no issues with playing/triggering these animations if they are already attached to the mesh’s animation component via the editor before runtime, but I want to assign only specific animation clips at runtime(during start/awake), without relying on having all of them attached beforehand via the editor.

I’ve tried calling the names of the clips explicitly as strings, doing AddClip, GetClip, etc, and a tons of other methods, nothing has worked thus far. Would I need to go the assetBundle route, or use the resources folder, or a different direction?

Is this possible? If so I appreciate any insight that can be offered. Thank you :slight_smile:

P.S. I’ve heard that adding anim clips at runtime can be taxing on mobile devices, if anyone can offer insight into any tests in that situation, I’d appreciate it. Thanks again.

The resources folder would probably work. It’s really the only way to load assets that aren’t referenced from the scene. You could also have the full array of animation clips in some MonoBehavior in some hidden manager object, and draw from that… I think that would work.

But why bother? Animation clips on an object that aren’t being played don’t slow things down or anything.