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
0
Question by Nonakesh · Dec 28, 2011 at 09:23 AM · transformarrayefficiency

Efficient wind on clouds

It seems as if my last questions were a bit too specific, but this time this is (probably) not the case!

I have a big array with clouds (planes with a cloud texture) and I want them to move with a constant velocity. This works well, but I recently bought Unity Pro and according to the profiler this cloud movement script is extremely expensive! Is there a more efficient way to do that?

 function Update(){
     for(var i = 0; i < cloudArray.length; i++) {
         var cloud = cloudArray[i];
         
         cloud.transform.position.x += cloudSpeed * Time.deltaTime;
         
         if(cloud.transform.position.x > mapSize.x + cloudBorderSize) {
             Destroy(cloud.gameObject);
             cloudArray.RemoveAt(i);
             
             NewCloud(-cloudBorderSize, Random.Range(-cloudBorderSize, mapSize.y + cloudBorderSize));
         }
     }
 }
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

2 Replies

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

Answer by Kilometers · Dec 28, 2011 at 10:21 PM

I don't see what is so taxing about it, but you could divide the loop between two updates using a coroutine if it is that bad. Pseudopseudocode:

 while (true)
 {
    for (first half of cloudArray)
    {
       ...
    }
    yield WaitForSeconds(0.0167);                 // 60th of a second
    for (second half of cloudArray)
    {
       ...
    }
    yield WaitForSeconds(0.0167);                 // Another 60th of a second, makes for a clean 30fps update of the cloudArray
 
 }

More on coroutines here: http://unity3d.com/support/documentation/ScriptReference/index.Coroutines_26_Yield.html

Comment
Add comment · Show 4 · 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 Kilometers · Dec 28, 2011 at 10:22 PM 0
Share

ALSO ALSO ALSO! The only reason I found this post is because I cam across your earlier question about a Point-in-Polygon solution. There, you said that you found a script to handle it. Where, might I ask, did you get it?

avatar image Nonakesh · Dec 28, 2011 at 10:34 PM 1
Share

The cloud script doesn't cause lag or something like that, but it makes huge "spikes" on the profiler! I think your script is a really good idea!

I don't know where exatly I got this script from and in fact I don't really understand it, but I made a few google searches. I used a sript similar to (maybe exactly) this one: http://www.ecse.rpi.edu/Homepages/wrf/Research/Short_Notes/pnpoly.html

If you can't get it working I can post the code tomorrow! (I'm on my laptop right now)

avatar image Kilometers · Dec 31, 2011 at 02:41 AM 0
Share

Thank you for that link. It is everything I needed.

avatar image Kilometers · Dec 31, 2011 at 05:34 AM 0
Share

Also, ins$$anonymous$$d of Destroy()-ing each cloud, perhaps you could just reset its transform.position when it has traveled beyond the map. This may help with the spikes.

avatar image
1

Answer by Kailas · Dec 31, 2011 at 09:20 AM

Replacing the destruction code with simply resetting their positions will improve efficiency since memory management is expensive.

Also, make sure that your clouds don't have colliders on them. As far as I know, having colliders (without rigidbodies on them) means that they are treated as static collision geometry. Meaning that moving them will cause the static collision system to rebuild itself every update, which is quite slow and totally negates its purpose.

Before you spend too much time on this, are the clouds inefficient enough to adversely affect gameplay? Is there a real reason to spend time improving them?

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 Nonakesh · Jan 01, 2012 at 09:22 PM 0
Share

The problem is that my graphics card is very strong and I can't really tell if it affects gameplay or not, so I try to make the code as effective as possible (with the help of the profiler).

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

Send array of transforms via RPC. [C#] 1 Answer

How to find the transform of a GameObject from an array. 4 Answers

How can i get ONLY the childrens of a GameOnbject with GetComponentsInChildren method? 5 Answers

Getting the transform from a GameObject list 3 Answers

problem extracting transform from an array 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