Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 harperrhett · May 23, 2020 at 03:48 AM · animationsynchronization

How should I sync animations?

So I have a custom script that takes in an array of sprites, and animates them frame by frame. It does this by invoking my custom IncreaseFrame function every 0.1 seconds (and changes the sprite to the next in the array). I have multiple sprites using this, but I want all of their animations to line up because they are conveyor belts, and conveyor belts should be moving at the same pace at the same time. I am not sure how to achieve this. Here's what I've played around with:


  • Creating a master script that calls IncreaseFrame remotely in every sprite animator script at the same time, but I can't figure out how to call the function in every script, and prefabs (the conveyors) won't allow me to manually assign a script that's not a prefab (i.e. my game controller gameobject would have the master script).

  • Inheritance, where all of the derived scripts are the sprite animator, but since it's class inheritance all of the base classes would still be separate objects, and would only start animating when created so they would still not be synced.

  • GameObject.SendMessage, which calls the function of all child objects, but I feel like it would get messy to put all of my prefabs under one parent object, although this might be the best option.

  • Somehow use Time.deltaTime to line them up, but I'm not sure how...


Any ideas would be very much appreciated! I have added a gif example of my game, all the conveyors animations should be lined up: Gif

y8musoy5wv.gif (51.2 kB)
Comment
Add comment
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

1 Reply

· Add your reply
  • Sort: 
avatar image
0
Best Answer

Answer by harperrhett · May 23, 2020 at 04:24 PM

I think I should be able to get a list or array of all gameobjects with the animator script and loop through it, activating them individually.

Edit: Yup! I figured it out.

 // Switch frame
     public void SwitchFrame() {
         // Increase frame
         frame++;
 
         // Get every script that is of sprite animator
         SpriteAnimator[] spritesToAnimate = GameObject.FindObjectsOfType<SpriteAnimator>();
         for(int i = 0; i < spritesToAnimate.Length; i++) {
             spritesToAnimate[i].frame = (frame % spritesToAnimate[i].frameSPR.Length);
             spritesToAnimate[i].UpdateFrame();
         }
 
         // Invoke in a certain amount of seconds, sort of used as speed
         Invoke("SwitchFrame", frameDuration);
     }

Hopefully this is useful to any other folk who aren't using the Animator.

Comment
Add comment · Show 2 · 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 Ricky-Brno · Mar 31, 2021 at 10:55 AM 0
Share

I'm super happy there are still people able to answer their own question (if they haven't receive any answer to it) AND in descriptive way how they solve it, rather than something like: "never$$anonymous$$d, I figured it out" as in the end of the day, this exists to help the community, to help everyone of us and not just to person asking the question. Just wanted to share my excitement and give my "kudos" - btw, glad you figured that out

avatar image harperrhett Ricky-Brno · Mar 31, 2021 at 02:09 PM 0
Share

Haha glad I could provide some hope! I’m just as tired as everyone else seeing unanswered questions closed 4 years ago, so I try to post my solution whenever possible :)

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

318 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 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

Animation syncronization trouble 1 Answer

Can the animation editor create local rotational data? 3 Answers

Problem with NavMesh link and animations 1 Answer

Adding animation clips via script 2 Answers

Reusing animation but they sync 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