n3xes

  • 24 mag 2020
  • Si è iscritto 1 apr 2015

    Harald,

    Due to this and a host of other issues, we are facing with 2D Toolkit and their abysmal support practices. We have decided that instead of trouble-shooting this issue we are just dropping 2D Toolkit, and developing our own solution. 2D Toolkit is garbage.

    Thanks for your help.

    Harald,

    So I reinstalled spine-unity again and pressed the "Enable TK2D" button. Now the project will compile, but the leg problems are still present and I get this error when I press play.

    <RI.Hid> Failed to read input report:
    The requested resource is in use.

    Additionally, show I can show you what is going on with the legs, how can we exchange files with you without posting them here?

    Please advise.

    Hey Harald,

    Yes, I tried to fix the issues myself. It compiled but then there was the weird leg behavior. So I rolled back.

    Still having some compilation issues though, even after a fresh install of spine-unity.

    Assets\Plugins\Spine\Runtime\spine-unity\Modules\TK2D\SpriteCollectionAttachmentLoader.cs(46,44): error CS0246: The type or namespace name 'tk2dSpriteCollectionData' could not be found (are you missing a using directive or an assembly reference?)

    Assets\Plugins\Spine\Runtime\spine-unity\Modules\TK2D\SpriteCollectionAttachmentLoader.cs(38,11): error CS0246: The type or namespace name 'tk2dSpriteCollectionData' could not be found (are you missing a using directive or an assembly reference?)

    Assets\Plugins\Spine\Runtime\spine-unity\Asset Types\SkeletonDataAsset.cs(45,10): error CS0246: The type or namespace name 'tk2dSpriteCollectionData' could not be found (are you missing a using directive or an assembly reference?)

    Please advise.

    • Modificato

    Hey,

    Last night I attempted to upgrade Spine to 3.8 from 3.7, and Spine Unity from 3.7 2019-08-05 to 3.8 2019-08-20. There were some errors related to 2D Toolkit after the upgrade and some of the leg art looked weird. So I had to revert. My animator would love to be able to use the features of Spine 3.8, but we can't until these issues are fixed.

    Please advise.

    2D Toolkit: v2.5.8.16
    Unity: v2018.4.6
    Spine: v3.8.61
    Spine Unity: v3.8 2019-08-20

    THAT WAS IT!!!

    Hi Pharan,

    I couldn't tell that the name parameter meant skin placeholder name.

    So for the sake of others reference. The "name" parameter of the Spine.Skin.AddAttachment(int slotIndex, string name, SpineAttachment attachment) method requires the skin placeholder name to be specified as the argument.

    So after some scaling issues are fixed by scaling the attachment's Height and Width using this code.

    float scaleSprite = 1.0f / (DataCollectionSpriteTK2D.invOrthoSize * DataCollectionSpriteTK2D.halfTargetHeight);
    
    attachmentRegionCollectionSprite.Height = attachmentRegionCollectionSprite.RegionHeight * scaleSprite;
    attachmentRegionCollectionSprite.Width = attachmentRegionCollectionSprite.RegionWidth * scaleSprite;
    

    The attachment is finally visible and the correct size. Only one problem left. It is not following the orientation of the bone. How can that be fixed?

    Thanks.
    -n3xes

    Hi Pharan,

    I tried this.

    private void Start()
    {
       RegionAttachment attachmentRegionDagger = NewRegionAttachmentFromSpriteCollection("Wpn-Dagger");       
    _indexSlotSkeletonSpineEquipmentHandLeft = SkeletonSpine.FindSlotIndex(NameSlotSkeletonSpineEquipmentHandLeft); _skeletonSpine.Skin.AddAttachment(_indexSlotSkeletonSpineEquipmentHandLeft, "Eqpmnt-Hnd-Lft", attachmentRegionDagger); _skeletonSpine.SetSlotsToSetupPose(); }

    Is this what you meant? Because it didn't work either. :bang: 😐

    -n3xes

    Hi Pharan,

    Thanks again for your help. I didn't notice that the height and width were 0, I only looked at RegionHeight and RegionWidth, and you are right, it should be expected that they would be invisible under those circumstances. It's actually kind of weird though that they have to be set when RegionHeight and RegionWidth are set to the size of the sprite. Why is that?

    As for UpdateOffset, I was calling it. I omitted it in the post for brevity's sake. This time I'm going to copy the exact code.

    public tk2dSpriteCollectionData DataCollectionSpriteTK2D;
    public String NameSlotSkeletonSpineEquipmentHandLeft;
    
    private Spine.Unity.SkeletonAnimation _animationSkeletonUnitySpine;
    private Int32 _indexSlotSkeletonSpineEquipmentHandLeft;
    private Spine.Unity.TK2D.SpriteCollectionAttachmentLoader _loaderAttachmentCollectionSpriteTK2DUnitySpine;
    private Spine.Skeleton _skeletonSpine;
    private Spine.AnimationState _stateAnimationSpine;
    
    private void Awake()
    {
       _animationSkeletonUnitySpine = GetComponent<Spine.Unity.SkeletonAnimation>();
    
       _loaderAttachmentCollectionSpriteTK2DUnitySpine = new SpriteCollectionAttachmentLoader(DataCollectionSpriteTK2D);
    
       _skeletonSpine = _animationSkeletonUnitySpine.Skeleton;
       _stateAnimationSpine = _animationSkeletonUnitySpine.AnimationState;
    }
    
    private RegionAttachment NewRegionAttachmentFromSpriteCollection(String nameSpriteTK2D)
    {
       RegionAttachment attachmentRegionCollectionSprite =
          _loaderAttachmentCollectionSpriteTK2DUnitySpine.NewRegionAttachment(null, 
                                                             nameSpriteTK2D, 
                                                             nameSpriteTK2D);
    
       attachmentRegionCollectionSprite.X = 0;
       attachmentRegionCollectionSprite.Y = 0;
    
       attachmentRegionCollectionSprite.ScaleX = 1;
       attachmentRegionCollectionSprite.ScaleY = 1;
    
       attachmentRegionCollectionSprite.Rotation = 0;
    
       attachmentRegionCollectionSprite.Height = attachmentRegionCollectionSprite.RegionHeight;
       attachmentRegionCollectionSprite.Width = attachmentRegionCollectionSprite.RegionWidth;
    
       attachmentRegionCollectionSprite.R = 1;
       attachmentRegionCollectionSprite.G = 1;
       attachmentRegionCollectionSprite.B = 1;
       attachmentRegionCollectionSprite.A = 1;
    
       attachmentRegionCollectionSprite.UpdateOffset();
    
       return attachmentRegionCollectionSprite;
    }
    
    private void Start()
    {
       RegionAttachment attachmentRegionDagger = NewRegionAttachmentFromSpriteCollection("Wpn-Dagger");       
    _indexSlotSkeletonSpineEquipmentHandLeft = SkeletonSpine.FindSlotIndex(NameSlotSkeletonSpineEquipmentHandLeft); _skeletonSpine.Skin.AddAttachment(_indexSlotSkeletonSpineEquipmentHandLeft, "Eqpmnt-Hnd-Lft", attachmentRegionDagger); }

    The sprite still does not show up. Here are the updated properties with Height and Width set.

    • attachmentRegionDagger "Wpn-Dagger" Spine.RegionAttachment
    • base "Wpn-Dagger" Spine.Attachment
      A 1 System.Single
      B 1 System.Single
      G 1 System.Single
      Height 500 System.Single
    • Offset System.Single[8] System.Single[]
      [0] -51 System.Single
      [1] -250 System.Single
      [2] -51 System.Single
      [3] 250 System.Single
      [4] 51 System.Single
      [5] 250 System.Single
      [6] 51 System.Single
      [7] -250 System.Single
      Path "Wpn-Dagger" System.String
      R 1 System.Single
      RegionHeight 500 System.Single
      RegionOffsetX 0 System.Single
      RegionOffsetY 0 System.Single
      RegionOriginalHeight 500 System.Single
      RegionOriginalWidth 102 System.Single
      RegionWidth 102 System.Single
    • RendererObject "Weapons-SpriteAtlasMaterial (UnityEngine.Material)" System.Object
      Rotation 0 System.Single
      ScaleX 1 System.Single
      ScaleY 1 System.Single
    • UVs System.Single[8] System.Single[]
      Width 102 System.Single
      X 0 System.Single
      Y 0 System.Single
      a 1 System.Single
      b 1 System.Single
      g 1 System.Single
      height 500 System.Single
    • offset System.Single[8] System.Single[]
      r 1 System.Single
      regionHeight 500 System.Single
      regionOffsetX 0 System.Single
      regionOffsetY 0 System.Single
      regionOriginalHeight 500 System.Single
      regionOriginalWidth 102 System.Single
      regionWidth 102 System.Single
      rotation 0 System.Single
      scaleX 1 System.Single
      scaleY 1 System.Single
    • uvs System.Single[8] System.Single[]
      width 102 System.Single
      x 0 System.Single
      y 0 System.Single
    • Static members

    At this point, I'm looking at everything. I can spawn a Dagger sprite (one that I can see) from the SpriteCollection into the scene. So I think the SpriteCollection is functioning correctly. I'm wondering if the problem could be with the Spine file.

    How should we proceed at this point?

    Thanks,
    -n3xes

    Hi Pharan,

    So I tried your solution. The bad news is it still didn't work, and all of the properties you mentioned had to be set are already set when this line is called.

    RegionAttachment attachmentRegionCollectionSpriteWeaponDagger =
                new SpriteCollectionAttachmentLoader(DataCollectionSpriteTK2D).NewRegionAttachment(null, "Dagger", "Dagger");
    

    Here are the properties:

    • attachmentRegionCollectionSpriteWeapon "Dagger" Spine.RegionAttachment
    • base "Dagger" Spine.Attachment
      A 1 System.Single
      B 1 System.Single
      G 1 System.Single
      Height 0 System.Single
    • Offset System.Single[8] System.Single[]
      Path "Dagger" System.String
      R 1 System.Single
      RegionHeight 500 System.Single
      RegionOffsetX 0 System.Single
      RegionOffsetY 0 System.Single
      RegionOriginalHeight 500 System.Single
      RegionOriginalWidth 102 System.Single
      RegionWidth 102 System.Single
    • RendererObject "Weapons-SpriteAtlasMaterial (UnityEngine.Material)" System.Object
      Rotation 0 System.Single
      ScaleX 1 System.Single
      ScaleY 1 System.Single
    • UVs System.Single[8] System.Single[]
      Width 0 System.Single
      X 0 System.Single
      Y 0 System.Single
      a 1 System.Single
      b 1 System.Single
      g 1 System.Single
      height 0 System.Single
    • offset System.Single[8] System.Single[]
      r 1 System.Single
      regionHeight 500 System.Single
      regionOffsetX 0 System.Single
      regionOffsetY 0 System.Single
      regionOriginalHeight 500 System.Single
      regionOriginalWidth 102 System.Single
      regionWidth 102 System.Single
      rotation 0 System.Single
      scaleX 1 System.Single
      scaleY 1 System.Single
    • uvs System.Single[8] System.Single[]
      width 0 System.Single
      x 0 System.Single
      y 0 System.Single
    • Static members

    I'm not sure where to even go from here. Please help.

    n3xes.

    Hi Pharan,

    So I'm still a little confused.

    region.Path = path; // path? Isn't the path just a reference to a sprite in the sprite collection? If not, what should I put here?
    //units scales are in Unity world space.
    region.x = 0; // Will this work just as a test?
    region.y = 0; // Will this work just as a test?
    region.scaleX = 1; // Will this work just as a test?
    region.scaleY = 1; // Will this work just as a test?
    region.rotation = 0; // Will this work just as a test?
    region.width = width; // Shouldn't this already exist in the sprite collection? If not, what should I put here?
    region.height = height; // Shouldn't this already exist in the sprite collection? If not, what should I put here?

    region.r = red value; // Shouldn't this already exist in the sprite collection? If not, what should I put here?
    region.g = green value; // Shouldn't this already exist in the sprite collection? If not, what should I put here?
    region.b = blue value; // Shouldn't this already exist in the sprite collection? If not, what should I put here?
    region.a = alpha value; // Shouldn't this already exist in the sprite collection? If not, what should I put here?

    region.UpdateOffset();

    The questions next to the lines of code make me think I don't understand something.

    n3xes

    Hi Pharan,

    Thanks for answering my question.

    In your answer, you mentioned that NewRegionAttachment was insufficient to define and prepare the RegionAttachment, and that I should mimic what normal loaders do. You also referred to the attachment loader I was using as "your SpriteCollectionAttachmentLoader".

    The fact is I'm attempting to use the Spine.Unity.TK2D.SpriteCollectionAttachmentLoader that is included as a module of Spine Unity, possibly incorrectly, which leads me to ask the next question.

    What is the prescribed order of operations, if there is one, to be able to load a sprite from a 2D Toolkit SpriteCollection, and attach it to a Spine Skeleton in Unity.

    Thanks Pharan.

    • Modificato

    We are currently using 2D Toolkit to manage atlases in Unity. We have one of our Spine animated characters implemented using 2D Toolkits' SpriteCollection, which alone works fine. This character has no weapon or shield bounding box or region attached to it in the Spine project. It does, however, have one bone for the shield and another for the weapon, and each of those bones have a slot and a skin placeholder.

    The weapons and shields that need to be attached exist in a separate 2D Toolkit SpriteCollection that we are using for equipment. I have been trying to follow examples, but it just does not work, no exception is thrown, it just doesn't show up. Here is what I have so far.

       
    public tk2dSpriteCollectionData DataCollectionSpriteTK2D; void Start() { _animationSkeletonUnitySpine = GetComponent<SkeletonAnimation>(); _skeletonSpine = _animationSkeletonUnitySpine.Skeleton RegionAttachment attachmentRegionCollectionSpriteWeaponDagger = new SpriteCollectionAttachmentLoader(DataCollectionSpriteTK2D).NewRegionAttachment(null, "Dagger", "Dagger"); int indexSlotWeapon = skeleton.FindSlotIndex("Weapon"); _skeletonSpine.Skin.AddAttachment(indexSlotWeapon, "Weapon-Dagger", attachmentRegionCollectionSpriteWeaponDagger); }

    Any idea what I'm doing wrong?

    Thx in advance.