1
\$\begingroup\$

I have an animator with two layers, an axe layer and a body layer.

I would like to animate the two in sync with each other. They are both 64x64 sprite animations, frame-by-frame bitmaps.

The problem I'm having is I can't figure out how to alpha blend the layers. The axe either plays and the player body becomes invisible, or the axe isn't visible.

I have a bunch of states like this which each return to an idle state. And link to an animation. I'd post a screenshot but I'm not allowed.

The axe layer is set to sync so the state machine looks the same, and I set the motion to the axe animations rather than the character body animations.

\$\endgroup\$
  • \$\begingroup\$ Please share screenshots of animator controller's settings of both layers for clarifications. \$\endgroup\$ – Inzi Butt Jul 14 '16 at 8:13
  • \$\begingroup\$ Layers are usually used for 3D animations that share common avatar and masking them. You said they are sprite animations. In case of sprite animation, axe/prop animation is done with main animation sprites or separate object animation with separate animator. Are you using any skeletal system to animate? \$\endgroup\$ – Sourav Paul Jul 15 '16 at 11:30
  • \$\begingroup\$ I'm not using any skeletal system, just sprite sheet animations. I originally tried this with two separate animators but the animations were out of sync. \$\endgroup\$ – dave Jul 15 '16 at 11:33
1
\$\begingroup\$

Layers are usually used for 3D animations that share common avatar and masking them. You said they are sprite animations. In case of sprite animation, ax/prop animation is done with main animation sprites or separate object animation with separate animator.

If ax's animation is a sprite animation then you have to create an extra state of animation that has both body and ax animation sprite drawn combined.

If it's a transformation animation then you can put the ax as a child object of the body and animate in the animation tab with the same body animation. Ax sprite can easily be synced that way in whichever frame you want.

If it's a component(enable-disable) animation you can easily do it as same above. All child objects and most of their components are accessible from animation.

For syncing with two animator call the ax's methods from body's animation's Animation Event. If ax has some proposes in the game like it goes in and attacks all the enemies in the scene then you should do it this way. If it just damages opponent when in attack state then go with single animator ways as you need.

| improve this answer | |
\$\endgroup\$
0
\$\begingroup\$

I know this is an old question, but I wanted to put in my two cents as well. Plus this QA is still popping up on Google. So... yeah.

Using Animation Layers with 2D Sprites is still useful. Just not in the way you the OP was trying. You might put the legs in layer1, the body in layer2, and the eyes in layer3. You'd have to re-implement the decision on which way the sprite is facing. But the legs could go walking while the arms are idle, or while the arms are swinging. Or the legs could be idle regardless of the arms state. And then the eyes could blink randomly regardless of whatever else you're doing.

So the whole purpose of those layers is trying to desync the animations.

I'm actually trying to look up the same thing as the OP so I can use layers from the LPC character creator to dynamically create characters. Demonstration and Sprite Sources

And I want to do this without going overboard on resources. I'm not entirely certain how I'll go about it, but here's an idea for it:

A script automatically generates and keeps track of children sprites. If there's a sprite object that it doesn't know about on the character, it will delete it when it updates the sprites on the object. There is one Animator Controller base. There will be like... 5 to 20 children sprites per character. Every sprite has an Animator Override Controller. The script that keeps track of the multiple sprites/controllers will iterate through the list to change/trigger parameters on all the controllers, based on one change/trigger given to the script.

I need to test how resource intensive this is. I also need to test how in-sync it is. If it's not in-sync enough, I'll need to add a reset trigger maybe...

In addition to that, I'm in the middle of writing an EditorScript to automatically process LPC animation textures, slice them into sprites, and animate them so they're all identical for any given selection of textures.

If the animations have slightly different timings though, the shared controller override idea would fail. The second option I'm looking at is making my own animator of sorts that just runs on a schedule and changes all the sprites based on an array passed in. But for some spritesheets (doesn't include a particular motion), it would require repacking, which I don't really want to do very much. So my auto-animator makes more sense than that...

| improve this answer | |
\$\endgroup\$
0
\$\begingroup\$

This is an old question and so this answer is way overdue. The only reason I am posting this answer is because I came across this question while also trying to solve the same problem in Unity 2018.4. It may well turn out that this answer wouldn't have applied to the 2016 version of Unity anyway. But here goes.

The solution to this problem is create a hierarchy of game objects. In your case something like:

Lumberjack 
   Body
   Axe

Lumberjack is just an empty GameObject. You then add an Animator to the Lumberjack and add Sprite Renderer components to both the Body and the Axe. Once you have done this create an Animator Controller and called it, say, Lumberjack Controller. Set this in the "Controller" field of the Animator (on the Lumberjack GameObject).

Lumberjack GameObject with Animator and Animator Controller set

Within the Animator pane, now create a new Animation clip by clicking on the Create button in the image below.

enter image description here

For the purposes of this answer let's call it "Lumberjack Idle". You can now click on "Add Property" and add Sprite Renderer (or Transform, etc) properties independently for both the Body and the Axe children of the Lumberjack GameObject. This allows you compose two completely independent animations. You can get control over which appears on top by setting the "Order in Layer" value under the Sprite Renderer components of Body or Axe. The image below shows some options you have when you first click on Add Property. The idea would be to add Sprite Renderer/Transform/whatever properties for both the Body and Axe.

enter image description here

Here's an example for a tank I animated recently which was composed of a Tank Body, a Front, and a Top Turret.

enter image description here

As helpful as you might find this answer, I would highly recommend watching this video on the topic as it covers many more techniques than I have presented here.

| improve this answer | |
\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.