Forum rules - please read before posting.

Outfits for 2D Sprites?

edited December 2018 in Technical Q&A

Imagine, for the sake of argument, that I set up a new 2D character in the usual way, using AC's Character Wizard. It could be a Player or an NPC, it doesn't matter. Animation will be via "Sprites Unity". Let's call this "Male01"

Normally when I do this I use pre-rendered sprites which already include the character's outfit. If I want to use a different outfit then I create a whole new character wearing this new outfit, and simply swop the Player or NPC during the game when they need to use it. That works ok in terms of how AC works, but is sub-optimal in other ways. So, in this case let's assume that I've pre-rendered JUST Male01's body

Let's also assume that I then create a new GameObject containing a Sprite Renderer and an Animator component. The animator has an Animator Controller set up that mimics the animations which the first character will use (idle, walk, etc), and uses a set of pre-rendered sprites that ONLY include an outfit. Lets call this "CasualOutfit"

Now, if "CasualOutfit" exactly shadows "Male01", with its position on-screen the same, its Animation, Animation Direction, and FrameNumber the same, and its SpriteOrder offset always greater than Male01's, then it will appear as if Male01 is walking around wearing CasualOutfit

That is exactly what I am aiming to do. The big advantage of this approach of course is that not just Male01, but Male02 etc, can all wear their own version of CasualOutfit, and not just CasualOutfit, but SuitAndTie, PoliceUniform, etc etc

But, how to achieve this?

Well, getting the things to move around the screen together is no biggee, I'll just make CasualOutfit a child of Male01's SpriteRenderer. (There will be some other niceties to be worked out - for instance I don't really want to have one different child for every potential outfit the character could wear, just a single "CharacterOutfit" GameObject, where the AnimatorController uses a different Controller each time. But, let's put that bit aside for now)

Second, the SpriteOrder. I'd expect to have to write a little bit of code to read the parent character's SpriteOrder and increment it, but I'm pretty confident I could do that

So, finally, getting CasualOutfit to precidely emulate Male01's Animation (idle, walk etc), Direction (U, D, L, R etc), and FrameNumber. They have to be exactly in sync, otherwise it will look a bit crap

And, this is the bit where I've come to a juddering halt, because I really don't have a handle on how I could achieve this. So, any advice or suggestions warmly welcomed

Comments

  • I don't see a need to have this as a separate Animator - you can use sub-layers in a single Animator to control the enabled state of child objects.

    The costume animations themselves could still be animated within the base layer, incorporated into the regular idle/walk/talk etc animations. Then, so long as each costume is in a separate hierarchy as a child of the Animator, you can animate each costume's hierarchy within separate sub-layers to control their visibility.

  • edited December 2018

    I think I understand what you're suggesting

    If I've got it correctly (and there's always a good chance that I haven't!) then you're suggesting that I set up an Animator sub-layer for each potential outfit that a character could wear. I'd then amend the character's idle, walk etc animations to animate the outfit in sync with their normal idle, walk etc animations, and set up a switch to change the visibility of the relevant outfit's sprite renderer child object depending on which outfit was to be displayed at a particular time

    One drawback I could see to that approach is that I would have to do it for every character that could potentially wear a particular outfit. With scores of characters (already existing) and scores of different outfits (planned, but not yet actually created), that could add up to quite a bit of effort

    The advantage of my initial suggestion (which was admittedly more of a thought experiment than an actual usable mechanic) was that I would only ever need to set up one set of animations and one Animator per outfit, and be done with it. I'd also not have to fiddle around with any character's existing animations or Animator

    BUT, I can see that your suggestion would actually work, whereas mine was just a vague pie-in-the-sky idea with no obvious way to implement it, soooo I'll experiment further with your suggestion

    Thanks, as always, for the feedback. I'm sure everyone here is grateful for the extraordinary amount of support we get from you for this product

Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Welcome to the official forum for Adventure Creator.