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.

How do I attach a skinned mesh to an animator?

Discussion in 'Scripting' started by Compressed, Jun 27, 2016.

  1. Compressed


    Sep 20, 2014
    Basically I have created and rigged a model in blender (let's call its mesh "mesh1") with couple of animations and then placed the model in a scene. I attached an animator to it and set it up to play the animations. No problems here, animations play and everything is fine.

    Now i added an empty gameobject (let's call it "new1") to the scene and to this object I added a SkinnedMeshRenderer component. Into the mesh field i placed the "mesh1".
    How can I connect connect this new SkinnedMeshRenderer (via script) to that existing animator in the scene (during runtime) so that it plays the animations as well ? (so there would now be two skinnedmeshrenderers playing the same animatons, both controlled by the same animator)
    I do NOT want to have two animators in the scene, i merely need to connect the SkinnedMeshRender placed in new1 to that existing animator in the scene.

  2. Simplified


    May 28, 2016
    Kind of hard to understand what you're trying to do, but I'm assuming that you want to replace the animator during runtime. Place your animator controllers in a "Resources" in your "Assets" directory. Use an animator override controller((so that you don't have to create an entirely new animator controller for each object) on your and do the following in a script:

    Code (CSharp):
    1. Animator animate;
    Code (CSharp):
    1.  animate.runtimeAnimatorController =
    2.             Resources.Load("Your controller here")
    3.             as RuntimeAnimatorController;
    You have to set your conditions before or after running that code of course.
  3. LeftyRighty


    Nov 2, 2012
    so you want one animator to govern two separate gameobjects? fairly sure they can't do that, so it'll have to be one animator per gameobject...