• Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
This question was closed Aug 28, 2018 at 09:44 AM by HaranStaubitz for the following reason:

The question is answered, right answer was accepted

avatar image
1
Question by HaranStaubitz · Aug 23, 2018 at 10:56 AM · animationanimatoranimator controllertriggering animation box collider

Multiple Game Objects with single Animator?

HI i have been working on a valve animation in my personal project.I added a triggered animation for the valve. but now as there are many valves with specifically the same animation and therefore the same animator.the animation is switched on for every object coupled with the particular game object...

Is there any way to animate only a specific object at an instance although many objects may share the same animator??(animate only the selected object(Valve) while other valves don't animate unless they are triggered.)

Note: all the valves share the same animator controller as they have the same animation with the same parameter.

Comment
Add comment · Show 10
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image eses · Aug 23, 2018 at 11:10 AM 1
Share

Hi @HaranStaubitz - Your question is bit vague, also you might consider editing your question, it is pasted twice in row, and there is a strange link in "object is" words.

"is there any way to animate only a specific object at an instance although many objects may share the same animator" - I don't quite get what you mean by this?

avatar image HaranStaubitz eses · Aug 24, 2018 at 06:48 AM 0
Share

hi @eses I'm sorry for that bad articulation of a question .I've edited the question as clear as i could, the simple way to say it is, "$$anonymous$$ultiple objects have the same animator so if a trigger animation is used by using a Collider, all the objects animate simultaneously rather than the triggered object only".

avatar image hexagonius · Aug 24, 2018 at 06:56 AM 1
Share

the default is to animate only one object. you must be calling all of them. how do you activate a valve to play it's animation?

avatar image Piyush_Pandey · Aug 24, 2018 at 07:07 AM 1
Share

I understood your problem. You can achieve this by using animation states. You just have to make different states for all the valves and then you can use the trigger to start/stop the animation.

avatar image HaranStaubitz Piyush_Pandey · Aug 24, 2018 at 07:33 AM 0
Share

@Piyush_Pandey So i have to like make a state for every valve?? which seems to be a round about way to like add new animator for each object, isn't it?

@hexagonius i animate using a trigger parameter to the animation and when the Character comes near the game objects' Collider, and presses a hot key the trigger is on. So in my case there are many such valves doing the same thing so if i trigger one valve all the valves get animated.

avatar image Piyush_Pandey HaranStaubitz · Aug 24, 2018 at 07:37 AM 3
Share

NO. Animator is a component while animation states are in an animator controller which is a parameter in an Animator controller. How is it better? ---because the Unity engine will have to handle lesser number of components.

Show more comments
Show more comments

1 Reply

  • Sort: 
avatar image
8
Best Answer

Answer by RocketFriday · Aug 24, 2018 at 10:09 AM

Step 1: So this is fairly easy to do, say that you make one animation for the valves that rotates to simulate turning it.


Step 2: Creating it with the animation tab in Unity should automatically create a animation controller, if not right clip in Project to create new.


Step 3: Put that animation in the animator as a state.


Step 4: On your next valve (or object) add a animator component, add the animation controller from the before and done.


All valves/objects use the same animation.

Your conditions are why all of them become activated at once.

Write a C# script to determine which valve should turn, the only parameters you should set in the Animator are those that decide which animation (or animation state) to play.

Finally, as for detecting which valve should play the turning animation use something along these line:

 using System.Collections;
 using System.Collections.Generic;
 using UnityEngine;
 
 public class ValveSelectorScript : MonoBehaviour
 {
     public GameObject[] valvesList; //put all your valves here from the inspector
     List<Animator> animatorList = new List<Animator>();
 
     void Start()
     {
         if (valvesList.Length >= 1) //make sure list isn't empty
         {
             for (int i = 0; i < valvesList.Length; i++) //NOTE: do "valvesList.Length - 1" instead, if you get index out of range error
             {
                 animatorList.Add(valvesList[i].GetComponent<Animator>()); //fill up your list with animators components from valve gameobjects
                 animatorList[i].enabled = false; //turn off each animator component at the start
             }
         }
         else
         {
             return; //if list is empty do nothing
         }
     }
 
     public void FindValve(string valveName)
     {
         if (valvesList.Length >= 1)
         {
             for (int i = 0; i < valvesList.Length; i++) //NOTE: do "valvesList.Length - 1" instead, if you get index out of range error
             {
                 if(valvesList[i].name == valveName)
                 {
                     //DO STUFF HERE
                     animatorList[i].enabled = true;
                     animatorList[i].Set(//enter parameter here\\); //set the animator parameter to play the animation
                     //Remember to turn off this specific animator to avoid turning when another valve is activated. i = the number of the animator in the list. if in the inspector it says: "Element 0" then this would be the same as "animatorList[0]"
                 }
             }
         }
         else
         {
             return;
         }
     }
 
 
     void OnTriggerStay(Collider other)
     {
         if (keypress)//whatever you do
         {
             string valveGameobjectName = other.gameObject.name;
             FindValve(valveGameobjectName);
         }
     }
 
     void Update()
     {
 
     }
 }


If you have any questions or need additional help, simply comment on this answer or my E-mail can be found on my profile.

I hope this helps, if you accept this answer please up vote it to help others facing the same issue find it easier.


RocketFriday

Comment
Add comment · Show 4 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image HaranStaubitz · Aug 24, 2018 at 11:35 AM 1
Share

@RocketFriday Thank you so much... i was about to do the same thing, and I saw your Answer and checked it out in a separate scene. it works the way i want, now all i have to do is incorporate it in my project. Thank You So much man and this was my first Question and i get a great answer like this. thank you so much really!!

avatar image paddia · Apr 11, 2020 at 10:06 AM 0
Share

THANK YOU! my Amigo you saved me a lot of time!

avatar image Dayls · Apr 16, 2021 at 12:55 PM 0
Share

For me it works not right. The animation only works correctly for the first object for which I created this animation, but I added this animation to other objects, and during animation they just move to the position of the first object. When I turn on the root movement for animation, all objects move infinitely in a strange direction.

avatar image larjun · Apr 21, 2021 at 09:10 AM 0
Share

Thanks! Also this 'https://answers.unity.com/questions/356442/using-the-same-animation-on-duplicate-objects.html' link could be useful.

Follow this Question

Answers Answers and Comments

244 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

How to handle multiple animation variants 1 Answer

Display additional animation on top of other animations 0 Answers

I'm still not get it how to mix/blend soldier character weapon aiming animation with walking animation ? 1 Answer

Multiple Animation Controllers 1 Answer

My Animator is acting Strange 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges