Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Join us on Dec 8, 2022, between 7 am & 7 pm EST, in the DOTS Dev Blitz Day 2022 - Q&A forum, Discord, and Unity3D Subreddit to learn more about DOTS directly from the Unity Developers.
    Dismiss Notice
  3. Have a look at our Games Focus blog post series which will show what Unity is doing for all game developers – now, next year, and in the future.
    Dismiss Notice

Help needed in creating a custom tool

Discussion in 'Animation' started by Laamato, Feb 23, 2021.

  1. Laamato


    Aug 27, 2017
    Hello everyone!

    I am creating a 2D game. I have hundreds of sprites. Processing everything manually is very time consuming. So I would like to automate this particular section of the workflow. The four steps I'd like to take are:

    1. On import create animation clips from pngs

    2. Create a new animation controller

    3. Assign new clips to this controller

    4. Loop through all of the clips and set the speed to .75f.

    I've done some research on these, but haven't yet been able to figure out the whole picture.

    Regarding 1:
    This is manually done by dragging a selection of sprites into the scene view, which then prompts whether I want to create an animation clip out of these. Am I somehow able to automatically skip this phase?

    I don't know if these help, but they could. I've found these from documentation: ModelImporter and AssetPostProcessor.

    I also found that I can construct an animation clip, but I'm stuck in how to add the sprites here.

    Regarding 2:
    Found this from docs:
    var controller = UnityEditor.Animations.AnimatorController.CreateAnimatorControllerAtPath("Assets/Mecanim/StateMachineTransitions.controller");

    Regarding 3:
    This is probably achieved via AddState/AddMotion method?

    Regarding 4:
    Found from docs:

    public class ExampleClass : MonoBehaviour
    public Animation anim;

    void Start()
    anim = GetComponent<Animation>();
    foreach (AnimationState state in anim)
    state.speed = 0.5F;

    Any help regarding to this much appreciated :) !
    Last edited: Feb 23, 2021