Aggressor

Sorry for title it should read Sprite Attacher Not Working

I edited a tiny bit of the sprite attacher but it doesnt seem to work when I try to dynamically load a sprite. Do you know why its not attaching the item?

The code is firing AND its getting added to the object like so:
img.png


Note that the slot is there:

img2.png


And if I manually activate this while the game is running (with a test object there) it does appear and disappear. And the logs show the slot and attachment are valid.

But its NOT appearing on the spine. The slot name is correct, too. Do you know why the sprite is not attaching and showing up?
public class SpriteAttacher : MonoBehaviour
{
// These are the slots that can be accessed
public static readonly string SlOT_HELMET = "helmet";
public static readonly string SlOT_ARMOR = "armor";
public static readonly string SlOT_MAIN_HAND = "mainHand";
public static readonly string SlOT_OFF_HAND = "offHand";

public bool attachOnStart = true;
public bool keepLoaderInMemory = true;

// Example of how to do this in the editor
//[SpineSlot]
//public string slotname;

private SpriteAttachmentLoader loader;
private RegionAttachment attachment;

public void Attach (string slotName, Sprite sprite)
{
var skeletonRenderer = GetComponent<SkeletonRenderer>();

if (loader == null)
//create loader instance, tell it what sprite and shader to use
// ANTHONY: This has been changed from Spine/Skeleton because it has artifacts when it spawns
// Using the Sprites/Default shader fixes this
loader = new SpriteAttachmentLoader(sprite, Shader.Find("Sprites/Default"));

if (attachment == null)
{
attachment = loader.NewRegionAttachment(null, sprite.name, "");
Debug.Log("Created Attachment");
}

// Get the slot and attach the object
Debug.Log("Adding sprite to " + slotName);
skeletonRenderer.skeleton.FindSlot(slotName).Attachment = attachment;
Debug.Log("Added to " + skeletonRenderer.skeleton.FindSlot(slotName).Attachment);

if (!keepLoaderInMemory)
{
loader = null;
}
}
}
Nothing below this changed.
Bu mesaja eklenen dosyaları görüntülemek için gerekli yetkilere sahip değilsiniz.
Aggressor
  • Mesajlar: 93

Pharan

It appears and disappears? For how long does it appear?
Are you possibly calling skeleton.SetToSetupPose anywhere? That can cause it to disappear because those newly attached sprites aren't part of the setup pose.
The alternative there can be skeleton.SetBonesToSetupPose but that will leave the slots unset.
Kullanıcı avatarı
Pharan
  • Mesajlar: 5366

Aggressor

Sorry for the confusing wording (2 am coding :bang: ).

What I meant to say is when I manually activate the slots (by clicking the box and unclicking in the SpineUtility script) it turns on/off the sprites.

However when I try to do it programatically, and dynamically load a sprite to attach to a slot, the sprites are not appearing on the spine at all even though the spine slot is valid, as is the sprite.

I don't believe skeleton.SetToSetupPose is called anywhere. Its literally the example script with only the minor changes seen above.
Aggressor
  • Mesajlar: 93

Pharan

2 AM is the best time to code. :D

I'm not too familiar with how Mitch implemented the loader and the attacher.

Did you check the state of the resulting RegionAttachment? (if it exists and other stuff)
Kullanıcı avatarı
Pharan
  • Mesajlar: 5366

Aggressor

Nothing is null. the sprite, the attachment, the slot, all valid :( Im really stuck haha

Interesting Caveat, running the BASE script from a fresh import also is not working now. Is it possible something is wrong my rig? Anything you suggest I look on the Spine at as to why the SpriteAttacher is not working if its the working code from the example?


I can 100% confirm this issue is now related ONLY to the newest spine model I got. I tried with our older models and it works.

I am not the artist so I dont create or import the Spine to unity. Do you know what I can look for as to why the sprite attacher is working on the old model but not the new? I checked the slot names and they match up so its not a slot naming thing...Anything else you can think of?

-- 10 Dec 2015, 01:11 --

OK GUESS WHAT. I found the problem.

It was SOOOOOOO super small I couldnt see it. :bang:

Part1.png


part2.png
Bu mesaja eklenen dosyaları görüntülemek için gerekli yetkilere sahip değilsiniz.
Aggressor
  • Mesajlar: 93

Pharan

LOL.

That would have made a great gif.

Why was it super small though? Was your SkeletonData scale huge? Or your sprite scale ridiculously small?
Kullanıcı avatarı
Pharan
  • Mesajlar: 5366

Aggressor

The sprite was about 100x too small.

You better believe the art team is buying me beer!
Aggressor
  • Mesajlar: 93

Pharan

No, but I mean what about the settings was causing it to be small?
Kullanıcı avatarı
Pharan
  • Mesajlar: 5366

Aggressor

Im not 100% sure I will look deeper into this over the weekend.
Aggressor
  • Mesajlar: 93

Mitch

Sprite attacher pays attention to the pixels/units size in Unity settings.
Kullanıcı avatarı
Mitch

Mitch
  • Mesajlar: 978

Aggressor

It was the Pixels Per Unit on the sprite. It was at 100.

solved.png
Bu mesaja eklenen dosyaları görüntülemek için gerekli yetkilere sahip değilsiniz.
Aggressor
  • Mesajlar: 93

Pharan

But 100 is the default. And I tried attaching a 100 pixels per unit sprite (a freshly imported sprite without any changes) to the Goblin sample scene and it was correctly sized.

Are you sure it wasn't your SkeletonDataAsset that was scaled at 1?
Kullanıcı avatarı
Pharan
  • Mesajlar: 5366

Aggressor

Its quite possible. I didnt import the spine. But if thats the case it would make sense!
Aggressor
  • Mesajlar: 93


Dön Unity