- Editado
Handling multiple characters with shared equipment
Hi, I'm building a game with many characters each of which can use a shared pool of equipment (weapons, armors, etc.)
The characters will probably end up as different Spine projects/rigs, the equipment will get used between them all.
Am I right in thinking that the simplest way to deal with this is to pack all the equipment into atlases, in Unity, then use the Spine SpriteAttacher utility script (or extension methods?) to assign sprites to slots?
Aurigan escreveuAm I right in thinking that the simplest way to deal with this is to pack all the equipment into atlases, in Unity, then use the Spine SpriteAttacher utility script (or extension methods?) to assign sprites to slots?
Unfortunately your post is ambiguous in what kind of atlas you meant: Do you want to put the equipment into a Unity-SpriteAtlas?
If so, then yes, it's easiest to use the SpriteAttacher
utility script or the available extension methods. The latter can be seen in use in the example scene Mix and Match
.
The alternative would be to export shared atlases from Spine for your shared equipment using atlas export by folder structure. This has been described in this forum thread here:
Can there be "Modular Assets"?
Exporting equipment atlases from Spine has the benefit of having more precise ways to ensure everything is positioned as desired, at the drawback of having to re-export the atlases when adding new pieces of equipment.
This is really helpful, thank you. I'd totally missed the separate texture export from Spine, to multiple atlases based on folder structure.
What's the workflow with adding eg. weapons? Let's say we have a single weapon referenced in the Spine skeleton/project but there are 20 weapons in the ../Images/Weapons folder. Texture packing from Spine will include all of those weapons ... but how do we then reference them from Unity/code? Or is the expectation that you manually add each to the Spine project file, set pivots, set it up as a skin?
Trying to test this out, I added an extra weapon image to my Weapons folder, re-ran the texture packer from Spine and, in Unity, the UVs are then broken for the weapons atlas (think I'd expect spine-unity to gracefully handle the changed atlas here).
Before:
After:
Reimporting the .atlas file in Unity doesn't do anything, reimporting the .json Spine file fixes the UVs for the weapons atlas but seems to create a new (unwanted) material named '<atlasname>-<pagename>-Screen' with the wrong shader (Spine/Blend Modes/Skeleton PMA Screen) assigned to all of the atlas sprites that have no fully opaque pixels (I think!).
Looks like this:
The blue areas are where there are 'glow' sprites set up in Spine to pulse transparency to make it look like the blue lines on her armor are glowing.
Once it's in this state the only way I could fix it was to delete the exported skeleton from Unity and re-export it from Spine then close/reopen the Unity scene to get the character to show up properly textured. So ... this seems like there are some bugs in how spine-unity handles file changes/reimporting ... guess it's still the same question fundamentally though - what's the expected workflow here? Thanks!
Edit - ok, so I tried just adding the weapon in the Spine file as a new skin ... looks like the runtime will fix things up if done like this. Still unsure how this would work across multiple Spine characters. Let's say there are 10 characters and we want to add 1 weapon for all of them to use this. Using this workflow we'd need to add a new skin to 10 different Spine projects and re-export all of them?
Aurigan escreveuWhat's the workflow with adding eg. weapons? Let's say we have a single weapon referenced in the Spine skeleton/project but there are 20 weapons in the ../Images/Weapons folder. Texture packing from Spine will include all of those weapons ... but how do we then reference them from Unity/code? Or is the expectation that you manually add each to the Spine project file, set pivots, set it up as a skin?
While you could add them at all Spine projects and adjust their sizes and offsets, it's most likely not the quickest way. At least you should then use the Spine command line interface to export all your characters quickly at once.
Another way would be to programmatically assign attachments, as demonstrated in the Spine Examples/Other Examples/AtlasRegionAttacher
example scene. The AtlasRegionAttacher
script at the FootSoldier
GameObject shows how you can attach a region from an Equipment atlas:
slot.Attachment = originalAttachment.GetRemappedClone(region, true, true, scale); // using the originalAttachment's bounds
or
slot.Attachment = region.ToRegionAttachment(region.name, scale); // without inheriting properties of another existing attachment
Aurigan escreveuReimporting the .atlas file in Unity doesn't do anything, reimporting the .json Spine file fixes the UVs for the weapons atlas but seems to create a new (unwanted) material named '<atlasname>-<pagename>-Screen' with the wrong shader (Spine/Blend Modes/Skeleton PMA Screen) assigned to all of the atlas sprites that have no fully opaque pixels (I think!).
The Screen
material is assigned because your skeleton is using the Slot blend mode Screen
at the respective slots. It has nothing to do with transparent pixels. This automatic handling of blend mode materials has very recently been added, previously you had to assign a BlendModeMaterialsAsset
manually.
If you don't want to use a Screen material, please set the respective material slot at the SkeletonDataAsset
under Blend Mode Materials
- Screen Materials
to your desired material (the same material without any suffix that the normal slots are already using). There is also a Spine Preferences section where you can customize the material templates for each blend mode.
As an alternative, you should perhaps set the slots in your Spine project to Normal
instead of Screen
if you don't want to use a Screen
material.
For the Screen materials ... it looks like Unity will only auto-create the new -Screen material when opening up the 'Blend Mode Materials' set of options for the skeleton data (or when manually selecting re-import in unity for the json asset). It's otherwise not created.
I did find the slots that were set to 'Screen' so have changed those to normal (thanks for explaining what was triggering this!) but ... seems like the way these materials are getting assigned/created has a bug still ... right?
Re. how to handle lots of weapons/armors, for anyone curious, ... have ended up with the animator I'm working with setting these up as skins, in Spine. All the shared weapons go in one folder, all the armor in another, all the art for each player character in another so we end up with a few small atlases.
Again, many thanks @Harald for the pointers along the way!
Aurigan escreveuFor the Screen materials ... it looks like Unity will only auto-create the new -Screen material when opening up the 'Blend Mode Materials' set of options for the skeleton data (or when manually selecting re-import in unity for the json asset). It's otherwise not created.
Yes, you have to trigger generation in some way, it would make no sense to check all SkeletonDataAssets every frame, that would make everything unusably slow.
Aurigan escreveuI did find the slots that were set to 'Screen' so have changed those to normal (thanks for explaining what was triggering this!) but ... seems like the way these materials are getting assigned/created has a bug still ... right?
Could you please describe what kind of bug or unexpected behaviour you encountered, and what you did that led to them occurring? We are happy to fix any issues that we can reproduce.
Thanks for reporting and for sharing your insights!