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 /
  • Help Room /
avatar image
0
Question by nabohall · Feb 01, 2017 at 08:09 PM · coroutinesupdate function

Using Coroutines and Update together

I am currently working on my first game, which is very similar to Tetris Attack. I'm working on the grid, and am running into a weird bug.

First, when the user clicks on two tiles, if they are adjacent, they will swap places. I got this working by using a coroutine. I then tried to get the tiles to move up, which I did in the Update function, by moving the transforms up by a small amount. These two things work independently.

The problem happens when I try to swap two pieces while the tiles are moving up, the two tiles stop moving up, switch places, then try to move up. This causes problem, as the rest of the tiles in the grid continue to move up while they are swapping places, and I'm not really sure what is going on.

TL;DR I have one game object that whose transform is being altered in both a coroutine and in the Update function, which is causing problems.

I think the solution is to use solely coroutines or the Update function, but not both. I'm just trying to get a better understanding of what is going on. If I need to add code or pictures, let me know and I'll add it.

Comment
Add comment · Show 3
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 Pengocat · Feb 02, 2017 at 03:48 AM 0
Share

Sounds like you are not stopping the old Coroutines properly? Hard to tell without seeing the code that is involved with the update and Coroutine. A Coroutine that yields by yield return null gets called right after the Update of whatever instance that started the Coroutine so normally it should not be a problem to use both if you start the Coroutine on the same instance as the Update.

avatar image nabohall Pengocat · Feb 02, 2017 at 06:40 AM 0
Share

I'll add some code later to try and make this clearer. But my Coroutine isn't being called inside my Update function. The coroutine is being started on a script attached to an individual tile, because I planned on having some tile types that can't be swapped. The Update function that is moving the tiles up is in a script on the grid. I might also be organizing my project poorly

avatar image Pengocat nabohall · Feb 02, 2017 at 12:06 PM 0
Share

The StartCoroutine doesn't need to be called inside the Update method but it is a good practice to use StartCoroutine within the same Class because then only one class handles the Coroutine.

0 Replies

· Add your reply
  • Sort: 

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

Unity C# Punching Coroutine not completing 0 Answers

Which is more efficient, Update() or a couroutine with while(true)? 1 Answer

use Update instead of Coroutines 1 Answer

Using Couroutines in another Class (Javascript) 0 Answers

Coroutine not working how I think it would? 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