Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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
1
Question by Sith92 · May 29, 2015 at 12:54 PM · c#scripting problemgameobject

Is it legit to make a blocking call inside of an Update() function?

Is it legit to make a blocking call inside of the Update function? Will it negatively affect somehow the program flow? For example, what happens if i put a Socket.Accept() inside of the Update function? I'm asking this since Unity just freezes when i do it

Comment
Add comment · Show 2
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 Sith92 · May 30, 2015 at 11:29 AM 0
Share

Thank you guys, your answers really helped me a lot

avatar image pako · May 30, 2015 at 11:41 AM 0
Share

You are welcome!

2 Replies

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

Answer by pako · May 29, 2015 at 02:01 PM

Unity freezes because it's waiting for the Socket.Accept() call to return, before it executes the next line of code in Update().

You'd better place the Socket.Accept() call inside a coroutine. Here's some example code to get you started:

     void Update ()
     {
 
         StartCoroutine(SocketAccept(newListeningSocket)); //SocketAccept() gets called and code execution continues immediately
 
     }
 
     IEnumerator SocketAccept(Socket listeningSocket)
      {
          Socket mySocket = listeningSocket.Accept();
 
         //other code...
  
          yield return null;
 
 
      }

Some references for more details:

http://docs.unity3d.com/Manual/Coroutines.html

https://unity3d.com/learn/tutorials/modules/intermediate/scripting/coroutines

Comment
Add comment · 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
1

Answer by karl_jones · May 29, 2015 at 12:56 PM

If you block/delay in the update then you will have an impact. The update is called each frame and wont move onto the next frame until it is completed so if you block then you are potentially reducing your frame rate.

Comment
Add comment · 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 CHPedersen · May 29, 2015 at 01:05 PM 0
Share

True. It is customary to put network code in a separate thread for exactly the reason you're describing.

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

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

How can I add the OnTriggerEnter function to all game objects that I instantiate? 1 Answer

Multiple Cars not working 1 Answer

Panel GameObject not activating 0 Answers

Unity 3D: how to make the game object increase the speed on continually tapping? 0 Answers

Scripting Problem: Gameobject activation acting up,Objects are activating when they shouldn't be (please help this is for a jam in 4 hours) 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