Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Question [2D Spritesheet] How to reuse animator with different sprite sheet.

Discussion in 'Animation' started by GMan_Wolf, Jun 1, 2020.

  1. GMan_Wolf

    GMan_Wolf

    Joined:
    Jan 30, 2016
    Posts:
    7
    Hi everyone

    Been trying to research and google this with no satisfactory results so far.
    I have a base sword sprite sheet with animations for the different attacks in different directions.
    I have created the animation controller and all the transitions/animation clips for everything and it all works great!.. for this base sword.

    I now want to add some new swords, they all follow the exact same transitions, the exact same X,Y movements, rotations etc etc. Is there any way to reuse the base sword animator?

    Others suggest animator override controller, but this still requires recording new animation clips for every single animation! which is crazy!

    So if attack up use the first 5 frames in the spritesheet, every single other sword is going use the first 5 frames in the respective spritesheet for attack up. How do i just swap the spritesheet being used for the animation ?

    Thanks
     
  2. GMan_Wolf

    GMan_Wolf

    Joined:
    Jan 30, 2016
    Posts:
    7
    So I came up with a solution that appears to work for now... but I dont really like it...

    I added a class to the animator gameobject with a an array of all the sprites from the spritesheet. and a method to change the spriterenderer to whatever sprite based on an index.

    I then went through all my base sword animations, removed the animation property that was changing the sprite and instead added a event there that calls the method and passes in whatever index i need for that part of the animation.

    Then whenever i change sword, I update the array of sprites with all the sprites from the new sword.

    So this lets me reuse the animator and transitions etc and all i need to do is make sure the sprites are added to the array in the correct order etc

    So far its working... so we will see. So if anyone has a better solution please let me know!.