Search Unity

  1. We are migrating the Unity Forums to Unity Discussions. On July 12, the Unity Forums will become read-only. On July 15, Unity Discussions will become read-only until July 18, when the new design and the migrated forum contents will go live. Read our full announcement for more information and let us know if you have any questions.

Unity2D: Calling individual sprites using Mechanim for frame by frame control

Discussion in 'Animation' started by jim_dodge, Feb 25, 2014.

  1. jim_dodge

    jim_dodge

    Joined:
    Jan 24, 2014
    Posts:
    3
    I would like to call some of my environmental animations frame by frame so that the environment tiles can be synchronized in the same animation state and cycled at irregular intervals en masse. I have written code to do this using a state machine that alternates the value of one bool from true to false with each step in the animation (eg. bool = true goes from frame one to frame two, and then waits until bool = false to go from frame two to frame three). I have used similar strategies to cycle between 3d animations (although the bools changed because of user input not time - both are code driven, so this should not matter), however, neither blend trees nor states allow me to switch between individual sprites using one bool. The animator does not appear to provide answers, but I am much less familiar with that than I am with Mechanim so there could be a solution with that tool which I am currently unaware of.

    I have a "Motion" based on a Spritemap that cycles perfectly, but does not allow the behaviour I desire. Possible (hacky) solutions include:
    1) I could create individual "Motions" with one frame of each animation and cycle between single frame "Motions" using my current code
    2) Do the same thing with "Motions" and use blend trees (1D) and change the code to increment a float that blends between sprites

    OR if anyone knows a better solution I am open to using Animator, rewriting my code, or doing Spritemaps manually to get frame by frame control


    FYI: I am not displaying any individual sprite for less than five frames, but my code allows me to change the sprite any frame after that
     
  2. jim_dodge

    jim_dodge

    Joined:
    Jan 24, 2014
    Posts:
    3
    After some research, it seems that the Animation window is my answer. Seems to involve placing a lot of both events and sprites (2 * 200+) but at least I know I can call a "PauseAndFindNextFrame()" function or something like that which will, in turn, call the UpdateAnimationState() code I wrote earlier. It would be nice to have a tutorial for specifically 2D applications of the Animation window. I had to watch some of the 2D Character Controller and most of the new 3D animation tutorials to extrapolate the information I needed. "The Animation View" the clip about moving cameras for cinematic flythroughs had crucial information I needed to set up the Animation window, which I did not know would be the solution at the time so it was quite hard to find. Here is a link for anyone with a similar problem, but I would hope for better resources in future! http://unity3d.com/learn/tutorials/modules/beginner/animation/animation-view