Search Unity

Using Same 2D Bone Animations for Different Sprites [Help!]

Discussion in '2D' started by TheFancyOtter, Nov 25, 2019.

  1. TheFancyOtter

    TheFancyOtter

    Joined:
    May 10, 2018
    Posts:
    15
    I'm using unity's 2D bone animation feature in my unity project. I have my player character animated, and now I'm trying to make an enemy using the same animation. The enemy has the same shape as the player, so I tried copying and pasting the player's rig onto the enemy. The player has the black outline, and the enemy has the red outline. In the preview section of the skinning editor, the rig works fine on both parts. When I originally pasted the rig onto the enemy, though the enemy rig didn't work completely properly. After I repainted the weights, though, the enemy rig worked fine. If you have questions or want more images, please message me. Thank you!
     

    Attached Files:

  2. blavatsky

    blavatsky

    Joined:
    Sep 23, 2019
    Posts:
    17
    I need to do the same thing, I think the answer is actually loading a different sprite in a script for the object itself, like into the sprite renderer. Then it will still be using the meta data (or, bone structure and weight) but with whatever image you load on top. I'll post some code if I get it working
     
  3. blavatsky

    blavatsky

    Joined:
    Sep 23, 2019
    Posts:
    17

    I have not tested this but it sounds promising
    https://docs.unity3d.com/Packages/c...7.1086817507.1574723668-1130798382.1569197026
     
  4. TheFancyOtter

    TheFancyOtter

    Joined:
    May 10, 2018
    Posts:
    15
    The link you've provided looks like it should be the answer. The problem is, though, that using it requires a sprite library asset that I don't have access to for whatever reason. When I try and go into the asset folder to create it, the sprite library asset doesn't appear. I thought that if I downloaded the psd importer then maybe the sprite library asset would come with it, but that didn't work.
     
  5. blavatsky

    blavatsky

    Joined:
    Sep 23, 2019
    Posts:
    17
    Ah, crap I was afraid of that too. I don't have photoshop, I'm just using PNG files with body parts in different sections and doing the skinning that way. Back to the drawing board...
     
  6. TheFancyOtter

    TheFancyOtter

    Joined:
    May 10, 2018
    Posts:
    15
    I'm pretty stumped on the issue right now. If anyone joins this thread with the same problem, please comment that you have a similar issue so hopefully someone with enough experience joins the thread! Otherwise, keep looking for something online.
     
  7. grolschie

    grolschie

    Joined:
    Nov 19, 2019
    Posts:
    3
    It would be nice if you could just copy/paste a character GameObject, and then swap out the .png file containing the SpriteMeshes with a virtually identical one (but colours edited). Is there an easy way to do this?
     
  8. blavatsky

    blavatsky

    Joined:
    Sep 23, 2019
    Posts:
    17
    Here is how I got this to work:

    1. Copy your main PNG or jpg (this is for non-Photoshop layers users) that has your character. Edit as you see fit

    2. Open the sprite editor on your 'parent' object. Go to Edit bones, select and copy the entire skeleton

    3. Open your child sprite in editor. Paste the bones in (you should get a dialog confirming on lower right). Go to generate geometry or whatever it's called and apply to get your colors/weights on the child and hit apply.

    4. In order to use this on an enemy or player, open their controller code and add a public variable of type 'Sprite', ill call it newSkin. In the inspector, drag your newly added child image into that slot from assets. When you want to swap that image in, call the code sort of like

    this.GetComponent<SpriteRenderer>().sprite = newSkin;