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 JoshuaAvalon · Oct 12, 2015 at 10:17 AM · programmingsynchronizationdesign-patterns

Can I ensure all script executed within 1 frame?

The title may be ambitious because I cannot think of a better but please read the following. GUI and the execution of script by event trigger (e.g. mouse click on button) should be asynchronous (correct me if I am wrong). When I click a button, it will trigger a chain of methods to execute. Can I ensure the chain of methods execute in 1 frame? In other words, during execution of the chain of methods, can I prevent player trigger another another event? I want to ensure the methods execute once at a time.

Once of the solution of I think of is to implement a event queue but I have to rework most of my code. Is there another way to do it?

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 Bunny83 · Oct 12, 2015 at 12:05 PM

A frame is defined by one run through the programs main loop. Unity's scripting environment uses a single Thread, so there is nothing happening asynchronous. Everything happens sequencially. I guess you use the new UI system? When you click somewhere Unity will do a raycast to determine what got hit. It immediately calls a callback method on the object that was hit.

Since it's a single thread it's not possible that a method somehow isn't finished when the frame is finished. The definition is actually the other way round: As long as a method is executing the frame isn't finished yet.

An exception are coroutines (which however aren't methods). A coroutines object can yield it's execution so it will be resumed later. If you don't use coroutines, everything that is executed in a frame will end in the same frame.

Comment
Add comment · Show 9 · 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 JoshuaAvalon · Oct 12, 2015 at 12:22 PM 0
Share

What I mean is that: $$anonymous$$ain Loop Awake->Start->...->OnGUI When the button is Click in between, should not trigger function is call on asynchronous?

avatar image meat5000 ♦ JoshuaAvalon · Oct 12, 2015 at 12:41 PM 0
Share

I think you mean

Awake->Start->...->OnGUI->OnGUI->OnGUI->OnGUI->...->OnGUI->OnGUI->OnGUI->OnGUI ;)

i.e OnGUI can run multiple times per frame.

Note OnGUI is the now half-legacy system.

avatar image Garazbolg JoshuaAvalon · Oct 12, 2015 at 12:44 PM 0
Share

No it will be called next frame. You can actually use the profiler to look at what is happening, record the moment when you click on your button and use the timeline to see what functions are called.

avatar image JoshuaAvalon Garazbolg · Oct 12, 2015 at 12:46 PM 0
Share

That mean if that onClick is long enough will freeze the GUI?

Show more comments

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

6 People are following this question.

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

Related Questions

Multiple Cars not working 1 Answer

Singleton design. 1 Answer

Several Questions about MVC pattern 0 Answers

Socket programming in unity 3 Answers

Multiple GUI.Labels to appear and disappear 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