- Home /
How do you add extra sub-assets into an asset while importing?
Hi,
I'm trying to write an asset post-processor that runs each time a model is imported. I want it to add new sub-assets into the asset, just like the Mesh
, Material
and AnimationClips
that you get by default when you import something. In this particular case, I want to add an extra AnimationClip
in that I've made procedurally.
Unfortunately, while I can hook into the process easily enough, trying to actually add the asset seems impossible. Here's the best I could come up with. It runs without error, but my new clip doesn't show up. The asset imports as usual but nothing's changed.
I also tried using AssetDatabase.AddObjectToAsset
instead, but it seems that's not intended to be using during import, instead to be called after an asset's been made?
public class MySuperModelProcessor : AssetPostprocessor
{
void OnPostprocessModel(GameObject g)
{
if (assetPath == "Assets/test.blend") {
Debug.Log("Adding new objects into asset: " + assetPath);
// Attempt to add an extra clip in there:
AnimationClip clip = new AnimationClip();
clip.name = "My New Clip";
context.AddObjectToAsset("my_new_clip_id", clip);
// ^^^^ This call seems like it should do the job,
// but instead returns without error and does nothing.
}
}
}