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 Caiuse · Mar 14, 2013 at 11:34 PM · instantiateraycastterrainvertexefficiency

Quickest most efficient way of instantiating a large amount of GameObjects

I'm looking for suggestions for the quickest and most efficient way of instantiating GameObjects at runtime, I'm procedurally generating a terrain on which I'm casting thousands of rays to the surface to check each hit position meets the spawning requirements ( can this be done more efficiently, baring in mind my terrain is spherical )

On each cast I establish whether the ground meets requirements ( in this case I check that the nearest hit vertex is coloured red ) and then instantiate my GameObject.

Currently this process causes the frame rate to drop to ~2FPS for a few frames, can this be done more efficiently?

In my specific case would I be better off iterating the verts on my terrain than leveraging the physics engine?

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
0

Answer by MountDoomTeam · Mar 15, 2013 at 01:56 AM

if you are doing a procedural terrain, instantiating is inherently slow as it takes an entire frame, it has to add lots of new details to memory every time etc. It's much faster to have many copies of your base procedural object somewhere miles out of range, and move it into place and change objects when you need them. so if you did a flat terrain, you would be going slower by instantiating every part, then by having say 144 chunks in the game and some of them marked in view and some of them as movable,

Also, the size of the mesh seems to have a disproportional impact on the slowdown, any meshes like 16x16/32x32 run really fast.

Also you should be looking at using yield as much as possible, you shouldn't use recalculate normals, you should do the normals based on invisible points just next to your vertices and then get their crossproduct if you can figure out which way they point etc. Like that it looks a lot better and you have more control over the normals calculation timing.

You can look around on the unity forums for a function queueing script, a task list queueing script, and yield command is very useful also,

for calculating the shape of your terrain, you can do that in between frames at different times from the mesh editing code , and you can do some simple processing on a different thread if the procedural code is simple or maybe even using arrays to read.

another problem you will find is Colliders, they take a long time and you should ideally only generator Collider for meshes that you are next to.

disable any scripts on terrain objects that use an update function, or just disable and enable scripts from the master script control as much as possible to keep it light and to lighten the memory.

That's about as many tweaks as I know for doing fast procedural terrain.

Comment
Add comment · Show 2 · 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 Caiuse · Mar 15, 2013 at 02:09 AM 0
Share

@ZoomDomain really appreciate that information, although I think my question wasn't worded very well, I've actually managed to generate the terrain fairly quickly, what I'm struggling with is tree and foliage instantiation. Would you still recommend having the objects preloaded and available "off screen"? I was also interested in the the separate thread idea, were you recommending arrays to managed by a different thread?

avatar image Caiuse · Mar 15, 2013 at 02:12 AM 0
Share

@ZoomDomain That method of calculating the normals was very interesting please could you also expand on it. How would you go about creating those "invisible points" would using the vertex positions and just offsetting them work?

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

11 People are following this question.

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

Related Questions

Instantiated Objects not being set at ground/terrain level?(Solved) 1 Answer

Use raycast to see if something else than terrain is under 1 Answer

Make an instantiated object match the slope of the terrain 1 Answer

Making a particle effect parallel to the slope of a terrain 1 Answer

Randomly some prefab instances have Character controller misaligned 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