• 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
Question by JGriffith · May 14, 2015 at 10:39 PM · animationmechanimstate-machinefsmstate synchronization

Multiple animators use the same controller / sate-machine or how to sync them?

This seems simple but I can't get it to work out....

I need multiple animators that all use the same controller asset, to have their state machines be synchronized, regardless of if they are enabled or not.

I almost need a "global" state machine that any instance of this animation reads from, but I don't know how to do it.

I have a system that creates a level out of prefabs. Each prefab contains 3 copies for the same fbx(model and animation). They all use the same Animator Controller aka Animator State-Machine.

However, because each has it's own unique animator component, and apparently it's own instance of the state machine, I'm running into trouble.

I can track and access all of my animators to set triggers on each one, however not all of their objects are on at the same time. So I can synchronize all the state machines that are on at the same time, but when new ones turn on, they are in their default "idle" state.

Comment

People who like this

0 Show 0
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

2 Replies

· Add your reply
  • Sort: 
avatar image

Answer by smallbit · May 15, 2015 at 09:53 AM

You can use This method. With this you can set the animation state start time, than any time you enable new component you will sync its animation with current. Maybe you will need to have some global timer to know where you animation is at the moment which would reset everytime animations makes a loop (can use an animation event for that).

Comment

People who like this

0 Show 1 · 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 JGriffith · May 15, 2015 at 11:13 PM 0
Share

This should do the trick if I am understanding you correctly.

I think I'm going to set up a global instance of the animated object and feed it's state and time values to that play method when each new animator is turned on.

I just need to read the docs some more on how to get the state info from the "master" animator.

Thanks!

avatar image

Answer by Crymorph · May 15, 2015 at 02:02 PM

I could see this being done through a StateMachineBehavior script using the SharedBetweenAnimatorsAttribute (Documentation on this can be found Here) Although it is intended to reduce the memory footprint it also seems to be capable of doing what you are looking for. You would attach the behavior script to the default start state and it could look something like this (untested):

 using UnityEngine;
 using System.Collections;
 
 [SharedBetweenAnimators]
 public class SyncBehav : StateMachineBehaviour {
 
     //Used to sync
     public Animator masterAnimatorComponent;
         
     // OnStateEnter is called when entering a state
     override public void OnStateEnter(Animator animator, AnimatorStateInfo stateInfo, int layerIndex){
             
         //I am sure this can be placed somewhere else but for demo purposes it's here
         if (!masterAnimatorComponent) {
             masterAnimatorComponent = animator;
                 
         } else {
             //Sync any required params, states or clips here.
         }
             
     }
         
 }


Comment

People who like this

0 Show 1 · 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 JGriffith · May 15, 2015 at 11:31 PM 0
Share

Very interesting.

I'm not sure I understand completely but am going to look into this further....

I'm fuzzy on exactly how I would sync the states from this state.

I don't think I'm understanding the sharedbetweenattribute or statmachine behaviors correctly....

It would essentially be an additional state in the state machine for my animator, correct?

It would be the entry state, that then would set the appropriate state when each new animator instance spawns based on the current state of the master, or am I misunderstanding?

Would I actually want the SharedBetweenAnimatorsAttribute at that point though?

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.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

21 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

Related Questions

How to animate the same object in the same time using built-in Animator? (for different properties, of course) 1 Answer

Is there a way to turn on a transitions hasExitTime on/off through code? 1 Answer

Makehuman mechanim Finger problem 2 Answers

[CLOSED] {Solved} small problem with Mixamo animation 1 Answer

Easier way of creating transitions in the animator? 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