• RuntimesUnity
  • Import external spine assets at runtime?

I'm making a "Mods" folder where custom skeletons/animations can be dropped, so Unity can import them at runtime without changing the Standalone game.

The texture works just fine, but is this possible with Spine skeletons/anims? I know you can create a skeleton at runtime using content data, but is it possible to import the spine json files & create the data at runtime as well?

Thanks!

Related Discussions
...

Yes, it is possible to import Spine JSON files and create the data at runtime in Unity. You can use the SkeletonDataAsset.CreateRuntimeInstance and SpineAtlasAsset.CreateRuntimeInstance methods to create a SkeletonDataAsset and SpineAtlasAsset at runtime from your JSON and atlas files. This process allows you to instantiate SkeletonAnimation GameObjects from these assets. Here's a simplified example based on the provided contexts:

// Assuming atlasTxt is your loaded atlas text, textures are your loaded Texture2D array,
// materialPropertySource is a Material to copy properties from, and skeletonJson is your loaded JSON text.
SpineAtlasAsset runtimeAtlasAsset = SpineAtlasAsset.CreateRuntimeInstance(atlasTxt, textures, materialPropertySource, true);
SkeletonDataAsset runtimeSkeletonDataAsset = SkeletonDataAsset.CreateRuntimeInstance(skeletonJson, runtimeAtlasAsset, true);

// Now you can create a SkeletonAnimation GameObject using the runtimeSkeletonDataAsset
SkeletonAnimation instance = SkeletonAnimation.NewSkeletonAnimationGameObject(runtimeSkeletonDataAsset);

This approach is useful for loading Spine assets dynamically, such as from a "Mods" folder, as you described. Make sure the assets (JSON, atlas, and textures) are accessible at runtime and properly loaded into Unity before attempting to create the runtime instances.

That works, and it returns a component, but it seems like existing components cannot be added to gameobjects.
So.. how would I go about actually adding that SkeletonAnimation component to my character script?
Edit: Nevermind, it's a gameobject with the component on it. So I just added it to my object as a child.

Wow, this was VERY easy to setup lol, and now I have external skeletons/animations that can easily be iterated on by artists or eventually modded by players. Sweet.