Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
13 Jun 22 - 14 Jun 22
sparklines
Close Help
  • 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 /
avatar image
0
Question by drodrii · Jan 11, 2015 at 12:14 AM · animation2dgameobjectanimatorchildren

Best Way - Animation - Multiple GameObjects.

Hello there, Happy New Year and best wishes for this one. I'll go straight to the point.

So, I want to make a GameObject Move. This gameObject will be My Player. I want this player to have some clothes. Shirt and a Pants.

hence I attached 2 GameObjects to the player.Shirt and Pants.

For this, I made One Sprite of a "naked" Player(and an actual 4 frame animation). Which I also made so for the Shirt and the Legs. The idea is that the 3 animations move when I press the Direction Button(Right arrow in this case).(GUI Repeat Button).

It works wonders if I press it once...But if a player double clicks the same button to move the 3 animations get unsynchronized and do something like this: Video of Bug on WorkSpace

Now, the animation has 2 states. Idle and Moving and its pretty much the same animatorController for the 3 gameObjects. I do have something like this, the actual code tells the gameObject and the children(Shirt and Legs are attached to Player) to move but the idea is the same.

 FixedUpdate(){
 if(_buttonisPressed)
       PlayAnimation();
 
 CheckIfButtonisPressed();
 
 }
 
 
 
 PlayAnimation(){
 
 //Tells the Animator to run the Move Animation.
 _attachedAnimatorComponent.SetBool(isIdle,False);
 
 }
 
 OnGUI(){
 
 if(GUI.RepeatButton(new Rect(Screen.width - (75 * 2) - 10, Screen.height - 75, 65, 65),"Move"){
 _buttonIsPressed = true;
 } else {
 _buttonIsPressed = false;
 }
 }
 CheckIfButtonisPressed(){
 
 if(_buttonIsPressed == true){
 PlayAnimation;
 }else {
 _attachedAnimatorComponent.SetBool(isIdle,True);
 }
 }

So, why does the animation Glitch out? Is there any way that I can tell the animations to synchronize?

Comment
Add comment · Show 14
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 sam2k13 · Jan 11, 2015 at 02:26 AM 0
Share

Try making an empty GameObject and making your three objects children of that object. Then, attach an animator controller to your parent GameObject. This will you allow to control all three GameObjects in one animation, keeping them from getting out of sync.

avatar image drodrii · Jan 11, 2015 at 03:23 PM 0
Share

@sam2k13

How would you call the three animations? Sorry, I added a gameObject, made it parent of the body,shirt and legs.

Created a script called AnimatorController, attached it to the parent. Here it is:

      public class AnimatorController: $$anonymous$$onoBehaviour{

      private void Set$$anonymous$$oving(bool moves){
     if(_bodyController != null)
         _bodyController.Set$$anonymous$$oving(moves);

     if(_shirtController != null)
             _shirtController.Set$$anonymous$$oving(moves);
     
     if(_legsController != null)
             _legsController.Set$$anonymous$$oving(moves);

}

}

This calls the animator on each gObject(body,shirt and legs) each time the button is pressed but if the player clicks the button fast enough the animations keep getting out of synch. What am I doing wrong?

Thanks for your time!!

avatar image drodrii · Jan 11, 2015 at 04:41 PM 0
Share

@wesleywh

Sorry to reply to you in a different thread. Happy new year and thanks for your help. So, I've updated my question to a more 'formal', myWork kind of related.

I've been trying various ways to solve this problem but no one has given me an actual solution....Im getting desperate and I don't understand why this would happen...

avatar image sam2k13 · Jan 11, 2015 at 05:30 PM 0
Share

Ins$$anonymous$$d of having three animator controllers on each game object just have one on the parent. Then when you create a new animation in this animator controller you can animate each game object in a single animation.

avatar image drodrii · Jan 11, 2015 at 06:21 PM 0
Share

@sam2k13

Thank you for your time. So,in this case, _shirtController is just a script that tells the AnimatorController which gameObject to animate.

_shirt(legs and body) have only 2 components attached. Controller script which sends itself as a gameObject just to know WHICH game object to animate and ofcourse the animator.

What line of code would you use to animate all 3 without having each controller? Sorry for being such a noob.... and again thanks for your time!

Show more comments

0 Replies

· Add your reply
  • Sort: 

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

26 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

Related Questions

2D Animation does not start 1 Answer

Animator - Stoping && Playing from Specific frames. 5 Answers

Sprite becomes invisible when set on animator 0 Answers

Combo Attack Animations in Mecanim 1 Answer

Object's sprite and collider are not at same position as transform 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