- Edited
Can there be "Modular Assets"?
In Unity, there is an option to re-use assets on the same character, for example:
You have one sword.png that you want to give the user the option to toggle on and off for, for all your characters. So I have done this before by using Unity's built-in animation tools of referencing a location on the bone and referencing to the one asset file. Since I have upgraded to Spine instead of the built in animation of Unity, is there that option of re-using only one PNG file such as sword.png on all characters?
What I am noticing when using Spine is that every character who can equip this sword.png has to now be added into it's own package, so that this sword.png is now in every single character's asset package. I want to just have ONE sword.png that exists for all of them to use to reduce asset redundancy, is this possible?
Hopefully my explanation is clear enough. Thanks in advance
Sorry for the late reply!
I'm not sure I understand your question correctly, please let me know if you are having different things in mind.
In Spine after export you will typically not use single PNG images per attachment, instead they will be grouped to an atlas with one or more atlas pages. You can control which images are grouped together on the same atlas page by organizing your images into subfolders: Texture Packing - Spine User Guide: Folder structure.
You may also choose to export multiple separate atlases (e.g. one atlas containing all attachments that are shared between skeletons) using the export workflow described above. Multiple Spine skeletons can share a single atlas asset and use a common attachment. The attachment name in the assigned atlas assets of a SkeletonDataAsset
must match for it to be found. While normally you will have a single atlas asset, with potentially multiple atlas pages (having one Material and one PNG file each), you can also assign multiple SpineAtlasAsset
s at your SkeletonDataAsset
.
Regarding asset bundles:
Every atlas description file (ending with .atlas.txt
) will have a SpineAtlasAsset
(with suffix _Atlas
) generated upon import, holding references to both the Material using the PNG image file (for each atlas page) as well as the .atlas.txt
asset. So when using separate asset bundles, normal rules apply regarding asset references across asset bundle borders. If you need to use separate asset bundles for Spine skeletons A
and B
and have a shared atlas asset shared_Atlas
, then you either need to make sure to not include the shared_Atlas
in any asset bundle but in the main game executable instead, or restore the missing references via scripts manually after loading the bundles.
A different approach, using single Sprite images would be to swap out attachments of a Spine skeleton at runtime with a replacement Sprite via Attachment.GetRemappedClone()
. This is demonstrated in the example scenes Spine Examples/Other Examples/Mix and Match
and Spine Examples/Other Examples/Mix and Match Equip
.
Hello Harold, thanks for the response and the references. I've been trying to execute what you have been saying, but I am not sure if it entirely resolves my issue. When I am exporting the character including the subfolder of "Swords", which includes many types of swords that is animated. Hopefully, I can toggle each sword on and off when the player selects it in Unity. A more specific question I have for you is, how do I export the images so that I can re-use only specific swords in the "Swords" folder in Unity?
To be more clear on what is happening is that I am only given the option to export the entirety of the project as a certain image file, hence .PNG for example. This option forces me to bundle up all the swords in the "Swords" folder, which leaves me no option, to reference each sword individually. Is there a work around for this, so that I can have the swords not bundled up with the rest of the project so that if a character can only use some of the swords, it can reference to one of the swords rather than all in a .PNG file. Or is this not an efficient way of thinking about it?
Another issue I am noticing is the naming convention, the packing of the .PNGs from subfolders are taking the project name itself, is there any way to make it so that it can have a re-usable asset name when packed, separate from the project name itself?
ckfw wroteTo be more clear on what is happening is that I am only given the option to export the entirety of the project as a certain image file, hence .PNG for example. This option forces me to bundle up all the swords in the "Swords" folder, which leaves me no option, to reference each sword individually. Is there a work around for this, so that I can have the swords not bundled up with the rest of the project so that if a character can only use some of the swords, it can reference to one of the swords rather than all in a .PNG file. Or is this not an efficient way of thinking about it?
I'm afraid I do not understand what you are trying to achieve or prevent here, or what the actual problem is. You can access individual swords by their name in the atlas, which they had before being packed together. The atlas name does not matter, it could as well be a non-human-readable generated hash like aiu4j6928egdfss4.atlas
and aiu4j6928egdfss4.png
, it is not referenced by this name in code later, you will access attachment names like "broadsword" or "dagger" from their input image names "broadsword.png" and "dagger.png" before packing.
I can recommend to have a look at the Spine Examples/Other Examples/AtlasRegionAttacher
example scene that comes with the spine-unity unitypackage, and check out the AtlasRegionAttacher
script at the FootSoldier
GameObject.
ckfw wroteAnother issue I am noticing is the naming convention, the packing of the .PNGs from subfolders are taking the project name itself, is there any way to make it so that it can have a re-usable asset name when packed, separate from the project name itself?
Please see Texture Packing - Spine User Guide: Texture atlas name.