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 KristofferH · Aug 24, 2017 at 08:30 AM · coroutineeventsystemuser interface

How to handle delays with UI interaction, i.e. while playing an animation

This is an issue I have had multiple times when creating an UI. Let's say I have a button that creates and destroys an instance of an object when toggled on or off. But there is an animation that scales the object from 0 to 1 to make it fade in, in a cool way rather then just popping up. The poblem is that this animation takes like 1 second, and if I toggle the button again before the animation has finished strange things can happen. Now this was just a simplified example but things like the destroy command does not fire has happened to me, so the object is still in the scene but the button is in the create state so pressing it again creates a new instance. Do you understand what I mean? There UI and the events in the scenes gets out of sync if the user is clicking to fast.

I tried using coroutines for the animation and that really made this a problem, in the end I hade to fix it by handleing the animation (usually some kind of Lerp), inside the the Update function with if-statements.

I also had an app with multiple modes, you started in Mode A and could press a button to go to Mode B and that also added a new button so now you cound either go back to Mode A or go forward to Mode C, and from Mode C you could go to Mode D or back one step to Mode B, but not two steps to Mode A (you had to go to Mode B first). And here I got similar problems with the animations when the user was to quick to press the new buttons before the 'mode transistion animations' had finished playing, and the scene ended up looking really strange because all the modes got mixed up all over the place.

When I say animation I'm mostly refering to coded Lerp animations, but even playing animation clips is of interest in this discussion.

So what I would like to know more about is this:

  1. How do you handle this "out of sync" problem between the scene and the UI?

  2. Is there a general good practice to adhere to?

  3. Is there something built into the Unity UI EventSystem I can use?

  4. How do you handle coroutines and UI interactions dependencies?

Please share your experience with creating fluent, dynamic and creative UI system with Unity :)

Cheers!

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
1
Best Answer

Answer by FortisVenaliter · Aug 24, 2017 at 05:11 PM

Yep, there absolutely is. What you want to do is build a state machine pattern. This common programming pattern is designed to manage and handle data flows. It works particularly well for situations like these.

In your simple example at the beginning, there would be three possible states:

  1. Not Started

  2. Animating

  3. Finished

Now, if the button was pressed, you would only enter the Animating state if the current state is Not Started. That would prevent the issues described.

Read up on the pattern on wikipedia for more information.

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 KristofferH · Aug 25, 2017 at 07:49 AM 0
Share

@FortisVenaliter That's an interesting point, thank you! Now, does the UI/EventSystem has something like this built in, or do I have to write it from scratch?

avatar image FortisVenaliter KristofferH · Aug 25, 2017 at 02:42 PM 0
Share

Uh, build it from scratch. It's really just an enum, a variable, and a few if statements.

Technically, Unity does have a state machine in the AnimatorControllers, but it would be a bigger pain to adapt that to your uses than to build your own.

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

72 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

Related Questions

Eventsystem requires window focus? 0 Answers

UI - Assigning Event Callbacks Via Script Fails on GameObjects Instantied Via Script 0 Answers

UI text visual glitching 1 Answer

Issues implementing UI event triggers via script 1 Answer

GearVR Back Button recognized as a click 0 Answers


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