#Animator still animating after being disabled

1 messages · Page 1 of 1 (latest)

noble wing
#

Original message

Each enemy in my game holds a baseball bat. This bat has an animator and does a crude swing animation. When the enemy dies, I (respectively) disable the bats animator, then deparent it, and let it fall.

For some reason, the bat is animated for a split frame after this, leading it to do it's idle animation, deparented, sending it to somewhere around Vector3 zero. Not good.

How could I fix this?

#

@spiral maple I recommend against using the emote you tried to use 😉

noble wing
#

Get it's name changed

spiral maple
#

Yeah I'll try

proven coral
#

maybe it has to do with event order, and maybe the animator still updates for the frame it was disabled?
what you could try if you can't find a decent way: store position and rotation of bat and apply that back next frame after unparenting.
but I think, disabling, or maybe even just removing (Destroy(GetComponent<Animator>())
should do the job, usually
not sure if it would be different if you change something in the order you do stuff

#

maybe you wanna set it to true so it doesn't go back to the default frame and instead keeps the active pose?

#

this reads like the default behaviour is that the object goes back to its original properties when the animator is disabled

spiral maple
#

I'll try that though, but I think the default behaviour is to just not update anymore

proven coral
#

that's not what the description of the property says at all

spiral maple
#

One thing to note though, the bat falls correctly when the enemy dies, and the problem only occurs when they get knocked over by a kick or thrown weapon

#

but that still puzzles me because in both cases it calls the same method

#

and it ALSO only occurs once the level has been reset a couple of times

#

its just really weird

#

i don't know what's causing it

#

its just upsetting

proven coral
#

strange, maybe there is a script execution order problem somewhere, but no idea

spiral maple
#

alright so i've cut the problem down

#

removed the rigidbody and everything, all i am doing is disabling the animator and then deparenting it and its still happening

#

i think this is a bug

spiral maple
proven coral
#

I linked the execution order link above
yeah the animator has a specific time where it updates, depending on the update setting,
coroutines are evaluated, by default at least, between update and lateupdate (but apparently before the internal animation update is update mode is "Update")

#

and aside from that, there is an implicit order in which the same methods of a MonoBehaviour script are called

spiral maple
proven coral
#

this applies only for custom script

#

s

spiral maple
#

so maybe I need to use OnAnimatorMove()?

#

add a boolean that says "hey we're supposed to drop so on the next AnimatorMove() you gotta disable and fuck off and go"?

proven coral
#

if you implement that method you manually have to progress root motion afaik

#

but some bool trigger thing like you describe somewhere might work

#

and you just set the position from last frame like i described above maybe

spiral maple
#

this is really really bad

#

holy fuck this worked

#
public IEnumerator disableAnimator()
    {
        Vector3 position = transform.position; //Store its position
        anim.enabled = false; //Disable the animator
        yield return new WaitForEndOfFrame(); //Wait til the end of the frame? Hopefully it's done it then?
        transform.position = position; //Move it back to its position
    }
#

this is what fixed it

#

to any CIA agents or officers of the law i would like to inform you i am going to light myself on fire in front of unity3d in san francisco

proven coral
#

ah nice

#

I'd probably include rotation too if necessary, but doesn't seem like that then