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 GADefence · Jul 24, 2011 at 04:16 AM · coroutinesplatmapalphamap

Coroutine and terrain

Right now I am calling a coroutine like this.

 Update
 {
 if (Gui.Button(new Rect(15,15,150,150),"test coroutine"){
 StartCoroutine(TestC(200f));
 }
 
 IEnumerator TestC(float P){
 float A = 0;
 while (A<P)
 Debug.Log(A);
 A++;
 }
 yield return null;
 }


My understanding of this is that TestC will take in 200 as a float (called P) and then do the while until A equals P - 1 (since it's < and not <=), at which point it returns nothing due to it being null. The yield is there since it tells the coroutine to yield to nothing and thus stop doing anything (I assume there are other names to use other then yield but that's the only one I know). I'm saying this to make sure I understand how coroutines work since I am new with them.

I do have one question though, aren't coroutines supposed to do code while your program runs so that you program doesn't jam? EX: A loading screen. If so, why does my program still freeze when running a coroutine? I'm doing the same thing as above, only I'm interating 2'000 entries and it still freezes instead of silently running like I expected it to.

Second question, I will post this in a seperate thread if no one wants to answer it here. I am going through my terraindata point by point to return the splats that are located there. My terrain is 2'000 units by 2'000 units. After reaching 512 sideways, I get error. . .

Texture rectangle is out of bounds (1999 + 1 > 512) UnityEngine.TerrainData:GetAlphamaps(Int32, Int32, Int32, Int32)

I actually had it working until I deleted my terrain and recreated it (my terrain seemed have unsynced from my scene, was the solution I found). I recreated the terrain and it's the only terrain in the scene, I also debug.log(terrain.activeterrain.terraindata.name) and it turns out to be the right terrain so I am curious as to what is happening. It looks like it trying to read outside of it's bounds (set to 512, even though my map is 2'000 and I debug.logged that too). Curious if anyone had this issue and know what setting it's reading for 512.

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 testure · Jul 24, 2011 at 04:25 AM

Formatted your code for you.

coroutines are not multithreaded. Unity is not multithreaded (yet). All processes happen on a single thread, which means if you have a while loop that runs infinitely and does not yield to the next instruction, it will hang the process.

To solve your problem, put your yield inside the while loop, not outside. This will ensure that the loop yields to the next instruction and doesn't hang.

Regarding your terrain question, I'm not sure- it might be better suited for its own question, since I came here because I know a lot about coroutines, but I haven't really used unity's terrains. others might do the same.

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 GADefence · Jul 24, 2011 at 06:01 AM 0
Share

Thanks mate, yield was what I was looking for. What's the purpose of a coroutine then?

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

3 People are following this question.

avatar image avatar image avatar image

Related Questions

A node in a childnode? 1 Answer

IEnumerable called within a EventHandler. Can this be done? 1 Answer

Updating a TextMesh buggy? 1 Answer

Terrain texture painting 0 Answers

Using Coroutines to increase Float values C# 3 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