2 different PSB files for idle/running. How do I change model during animation?

Hey!

I’ve been fiddling around with this for many hours now and I can’t seem to find a solution. I’ll try to explain my issue to the best of my ability:

  1. First I created a 2D sprite in photoshop for my players idle stance, and put all body parts into separate layers. I exported it as .psb and imported it in Unity. I used Unity’s sprite editor to rig my 2D sprite. I then used 2D IK manager, and proceeded to make a little idle animation for this sprite.

  2. I then needed to create a different 2D sprite for my running animation, as the idle stance would look weird if I animated it to run. I did the same process as step 1, exported it as .psb and imported it in Unity. Once again, using Unity’s sprite editor, I rigged the running 2D sprite and proceeded to create the running animation.

  3. I dragged the idle stance prefab into my scene and attached an Animator component to it. From here I opened the animator grid and then dragged my running animation into it. I created transitions between the idle & running animation, added a boolean parameter “isMoving” and created a script that checks if the character is moving in order to switch between the animations.

  4. Now my issue is that the idle sprite is being used for both the idle and running animation, instead of changing the model to the running model, which I used to make the running animation. It’s like my animation has just been placed onto the rig of my idle sprite. It looks really weird and I don’t know how to change the entire sprite to that of the running animation.

I’m guessing this is related to the fact that I dragged my idle sprite into the game scene and didn’t create a parent gameobject for the idle and running sprites. But since these aren’t regular “sprites” anymore but rather prefabs with layers, I can no longer use a “Sprite Renderer” component to show the sprite. So I’m not sure how else to do this.

Does anybody know how to fix this? Thanks in advanced

I have a working idle, run and a jump animation. Here are 3 things I made mistakes on, and maybe this helps you.

  1. Check the Animation tab, and the menu on the left to make sure that you did make two different animations and didn’t accidentally make the second animation over the first one.

  2. Compare your code with mine. Maybe a spelling mistake or missing bracket somewhere? I used isMoving as a variable name as well.

  3. It sounds like there a transition between your idle and run (isMoving = true). Is there a second transition from run back to idle (isMoving = false)?

8955825--1229871--upload_2023-4-17_20-0-38.png

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class AnimController : MonoBehaviour
{
    private Animator anim;

    private void Start()
    {
        anim = GetComponent<Animator>();
    }

    private void Update()
    {
        if(Input.GetKey(KeyCode.A) || Input.GetKey(KeyCode.D) || Input.GetKey(KeyCode.LeftArrow) || Input.GetKey(KeyCode.RightArrow))
        {
            anim.SetBool("isMoving", true);
        }
        else
        {
            anim.SetBool("isMoving", false);
        }

        if (Input.GetKey(KeyCode.Space))
        {
            anim.SetTrigger("Jumping");
        }
    }
}

You are correct here.

From my understanding, it’s essentially needing to swap from one prefab to another prefab.
One possible way would be to have the ‘Idle’ and ‘Running’ prefab under a parent GameObject. Your animation controller will be on the parent GameObject that determines when to disable/enable the prefabs depending on your game state.