Forum rules - please read before posting.

Parenting sprite to player object makes weird animation bug

edited September 2021 in Technical Q&A

Hey there,

This is my first time using AC with 2D sprites so I'm really new to this, using v1.73.8

I have a small sprite I'm trying to parent to the player gameobject which is also a sprite of course via action list.

The small sprite has its own animator and one of the animations moves the small sprite across the screen.

The problem is if I try to play the game with the sprite parented to the player (via action) AND the moving animation is there in the animator, the sprite just spawns way off screen (without even calling the animation) and does all the animations there off screen.

But if I delete the animation from the animator then it spawns in front of the player like it should and plays all the other animations just fine. It also works if I set parent so it appears on the player like I want it to but then clear it straight after... but I need it to follow the player so clearing parent won't work for me.

This doesnt happen with any other animation though they are only messing with the sprite alpha, it seems to just be position.

Does anyone have any clue why this is happening lol

Thank you

Comments

  • Can you share screens to illustrate this? It's a visual problem, so it'll help me understand the issue

    Also: what's the wider intent/context here? If possible, it's typically better to incorporate the other sprite into your Player's regular Animator - a sub-layer can be used to control the sprite's visibility.

    You say one of the animations moves the sprite, but which animation is its default? Check the Animator at the time the issue occurs.

  • edited September 2021

    Hi Chris,
    Its a sprite that appears when you're about to go into 'battle mode' and remains visible as the camera switches to the UI battle camera while the rest of the bg fades out. Ive now tried to parent this sprite to the player and now the sprite fader does not work. It says the action is green/playing but it does nothing.

    Ive also moved the small sprite's animations to the player's animator and put them on a new layer for that sprite but all those animations dont play either (with and without the animator component on the small sprite)

    I uploaded all the relevant images i could think of

    https://imgur.com/a/mwxwKQZ

    Its probably something dumb i'm missing but again im new to the 2d side of AC ahhh

  • I'm still trying to visualise what effect you're going for in-game.

    Your Object: Animate Actions still refer to the sprite, but it no longer has an Animator attached. You'll need this Action's Animator field to point to your Player's root, if that's where it now is.

    Is your Player + sprite part of the scene file, or spawned in at runtime? Your OnStart's Object: Fade sprite Action suggests a scene object is being affected.

  • Hi Chris,
    So do I use object animate on the player object rather than the heart sprite?
    And they are both of the scene file.

  • If the Animator is the same as the Player's, yes.

  • edited September 2021

    Hi Chris,
    So sorry that this is taking so long to resolve!
    If I do that and make the heart sprite animator the same as the player's then it just does this:

    And the heart sprites turns into the player's sprite (assuming from the player's idle animation)

  • edited September 2021

    These aren't issues specific to AC, but with how Unity's animation system works.

    If you move your animation to be shared by your Player's animator, you'll need to update the animations themselves to match it.

    Since the Player's Animator is now a parent of the object you're trying to animate, you'll need to update those animations to affect the child.

    The warnings you're getting are coming from Unity, saying that the animations you're calling for, e.g. soulstopblink, are not present on the Animator.

  • edited September 2021

    Hi Chris,
    Getting somewhere now, only a few issues!

    1) It only 'reads' the animations if its on the base layer, I made a separate layer for the heart like recommended and I'm not entirely sure how to get it to 'read' that.

    2) The other issue is that on start, the heart takes/copies the player's idle animation so it uses the player sprite instead of the heart. Again I sorta assumed if I made the layer default state the heart on the heart layer it would use that, but its on the base layer so its instead using the player sprite...

    3) Also, now if I try to add the animation that moves the heart sprite into the animator (like mentioned in my og post), my player gets stuck in place when I try to walk... but fixes itself if I delete all the keyframes

  • 1) Do you mean that the animation is playing in the Animator, but it has no visible effect? Be sure to give the layer a non-zero weight.

    2) Are you using multiple Animators? That's most likely to occur if you have the Player's Animator Controller asset associated with another Animator attached to the heart.

    3) Be sure that your keyframes only affect the position of your heart child, and won't interfere with your Player's sprite/root position.

    These still don't sound like AC issues, and I'm lacking context on what it is exactly you're trying to animate and how. It might be best for you to take things from the top and explain the fundamental situation, rather than the problems with the way you're trying to solve it.

  • Ahhh I'm going insane
    Just gave the layer a weight of 1
    Deleted the animator from the heart sprite
    Redid the keyframes to ensure the heart sprite was selected while doing it
    Now the player is still stuck in place /and/ the heart sprite won't animate at all

    Basically there's the player, and it's the parent of a heart sprite. When the player goes into battle the heart sprite appears where the player was and blinks for a few seconds while it transitions to the UI camera for the battle menu (with only the battle UI culling mask including the heart sprite, so fading out the background).

    Problem is of course the heart sprite refuses to animate and the player gets stuck if theres an animation the moves said sprite in the animator even if it isnt used. But the player is free if I delete it... :D

  • I can't give any more advice without seeing exactly what you've got, I'm afraid. It's too specific to your situation.

  • Hi Chris,
    Sorry for the confusion,
    I put everything I could think of here: https://imgur.com/a/WT378gL

    I hope it helps and thanks so much for your time I really appreciate it

  • Don't parent the MainCamera to your Player - it can cause positioning issues.

    Any animations that affect the heart sprite need to be in a sub-layer. Each layer can only play one animation at a time, so the base layer must only have player animations. Otherwise, playing a heart sprite animation will cause your player to stop animating.

    Any "Object: Animate" Action that controls the heart sprite on the player should have its "Mecanim layer" set to "1". "0" represents the base layer.

    If you use "Character: Animate" Action instead, you can check "Is Player?" to avoid having to assign the Animator component inside the Action.

    You can't control the sprite's color/alpha channel both through animation and the Sprite Fader component. They both control the same property and will conflict with one another. Either use the Sprite Fader to control all changes to the sprite's alpha, or use Animation only.

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.