This is AI generated question:
I'm currently optimizing a Unity project that needs to render a large number of Spine characters (testing with 150-500), and I've hit a solid wall trying to implement a hot-update system for character skins at runtime. I'm hoping someone here can point me in the right direction or correct my approach.
What I've Achieved (for context):
Optimized rendering significantly. By using SpineCharacterRandomizer and calling OptimizeSkin(), I can render each character with exactly 1 draw call, regardless of texture complexity. The massive FPS boost is great.
I've also gained 15-20 FPS by aggressively reducing bones/vertices/keyframes in the editor and enabling USE_FAST_SIN_COS_ATAN2_APPROXIMATIONS in MathUtils.cs.
The Core Obstacle: Runtime Hot-Updating
The project requires downloading new skins (textures/SkeletonData) from a server post-launch without rebuilding the app. I've tried two approaches, both of which failed. I need to understand why these fail fundamentally, and what the correct architecture is.
Attempt 1: Raw Texture Load & Material Swap
My idea was simple: load a raw texture at runtime, create a new Material, and inject it into an existing skin's attachment.
Exported a base character (skeleton + animations) from the Spine Editor.
At runtime, loaded a new .png texture from disk/server.
Created a material with the Spine/Skeleton shader and the new texture.
Attempted to find the correct slot/attachment (e.g., RegionAttachment) and set its renderer to the new material/texture.
Result: Failed. The mesh didn't update correctly, or the new texture was placed in the wrong position. It felt like I was missing a crucial step in rebuilding or re-mapping the attachment's UV coordinates or mesh bounds. Is this approach even viable, or is the entire Skeleton/Skin structure too baked-in for this?
Attempt 2: Two-Export Base & Skin Swap (Based on an AI's Suggestion)
This was suggested as a workaround, which I tested but couldn't get working:
Export A: A base character (no skin textures, just skeleton + animations).
Export B: A separate export containing only the skin attachments (no animation).
At runtime, load both. Apply the Skin from Export B onto the Skeleton from Export A using something like skeleton.SetSkin().
Result: This failed. The skeleton and animations worked, but the skin from the second file never correctly attached. My assumption is that the internal indices for slots/attachments between the two exports didn't match, causing the skin to silently fail. Is there a correct procedure for "grafting" a skin from one export onto a fresh skeleton from another? Can this be done at runtime without merging them in the editor?
The Central Question:
With my current experience, am I missing a fundamental rule about the Spine-Unity runtime? Is there a proven, documented workflow for loading a complete new character structure (skeleton + skin) or just a skin sheet from an AssetBundle or raw files at runtime? Any code snippets, high-level architecture advice, or a definitive "stop, you're doing it wrong" would be incredibly valuable.
Thank you for your time and expertise. I'm happy to share my current code implementation of the failed attempts if it helps diagnose the issue.