Jump to content

CommonState's walk and run states do not loop properly

Leonardo Cox
  • Pending

CommonState's AddWalkStates and AddRunStates have an issue where in the "walk" and "run" states respectively don't loop properly, eventually causing a desync with the intended timeevents.

table.insert(states, State{
        name = "walk",
        tags = { "moving", "canrotate" },

        onenter = function(inst)
			if fns ~= nil and fns.walkonenter ~= nil then
            inst.AnimState:PlayAnimation(get_loco_anim(inst, anims ~= nil and anims.walk or nil, "walk_loop"), true)

        timeline = timelines ~= nil and timelines.walktimeline or nil,

		onupdate = fns ~= nil and fns.walkonupdate or nil,

		onexit = fns ~= nil and fns.walkonexit or nil,

        ontimeout = walkontimeout,

The main culprit seems to be the method of looping the states. Which is the Timeout.


The state attempts to convert the animation length into an accurate timeout to properly loop the state, however due to either an error on GetCurrentAnimationLength or executing Timeout, there will be a very small delay causing the state and animations to desync. It's not noticeable on most things in game since the delay is so short it takes awhile for the desync to be noticeable, but it is an issue regardless.


While I don't know the technical reasons for choosing this method or if fixing it will cause issues elsewhere, I know of other methods of state-looping where the timings stay synced. A common one I use for custom mobs and playable pets is setting a "animqueueover"/"animover" event to replay the state.

events =
            EventHandler("animover", function(inst) inst.sg:GoToState("idle") end ),    

Steps to Reproduce

-Have a mob or entity that uses CommonStates.AddWalkStates or CommonStates.AddRunStates walk/run continously without stopping. 

-Wait until the eventual desyncs happen.

  • Like 3
  • Big Ups 1

User Feedback

There are no comments to display.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Create New...