Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 11 Next capture
2021 2022 2023
1 capture
11 Jun 22 - 11 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 Wizeon · Jan 15, 2010 at 12:46 AM · gameobjectinstantiategraphicsdrawcalls

Combine objects instantiated at runtime

I'd like to combine objects to reduce the drawcall amount. Currently it goes to thousands so it's really bad. I'm creating the terrain with the following basecode:

function Start() {
var width:int = 100;
var height:int = 100;
for(i = 0; i < width; i++) {
for(ii = 0; ii < height; ii++) {
Instantiate(Resources.Load("Ground"), Vector3(i,0,ii), Quaternion.Euler(0,0,0));
}

Should I combine the whole thing as one object? They're plain planes just next to each other. I'm planning on using a 1024 x 1024 texture with all the different terrain types and assign it to all planes. Will this approach be any good? 1024 x 1024 is needed considering the amount of different tiles I'll be using.

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
2
Best Answer

Answer by Tetrad · Jan 15, 2010 at 11:52 PM

If you're using Unity 2.6+ there's a built-in function on Mesh called CombineMeshes that's probably preferable over the standard assets CombineChildren script. See the documentation here: http://unity3d.com/support/documentation/ScriptReference/Mesh.CombineMeshes.html

Some caveats of doing what you're suggesting though:

  • If your "Ground" object has collision, triggers, or really anything other than a mesh/mesh renderer on it, you'll probably need to keep the original game object you instantiated around with the mesh renderer disabled/destroyed.
  • [I may be wrong on this, but] Unity doesn't know when exactly it's safe to delete a mesh. Make sure you're not leaking meshes after creating them with CombineMeshes.
  • A single mesh in unity cannot have more than 65000 verts. If you're trying to combine an entire level made up of relatively small, detailed tiles, this might be an issue. You'll have to check manually to make sure your vert count is below that, and if it isn't generate multiple meshes.
  • If you can, make as many of your tiles use the same material as possible (i.e. atlas everything you can), so make it so that you have as few meshes as possible. CombineMeshes will make each mesh it's own submesh, but I don't know how efficient that is at combining draws of submeshes with the same material.
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
2

Answer by Jaap Kreijkamp · Jan 15, 2010 at 12:59 AM

You better look at how to make a Mesh object as this will give way to many objects. You could try to merge them with the CombineChildren script from Standard Assets, but will probably give quite a delay. Also, instead of Resources.Load use a var Transform as global variable and drag the Ground prefab to it. If you use Resources.Load Unity won't know that you're actually using Ground in your project and if you don't have any other direct references to it, will not include it in the build of the project.

If you have only one Ground type it isn't to hard to generate the Mesh with some little coding, if you need help with that, let us know.

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 Wizeon · Jan 15, 2010 at 01:12 AM 0
Share

Well to my understanding all assets included in the resources folder are included even if not referenced anywhere. And a build with that code works perfectly so that hasn't been an issue. I'll need the plane to have UV map so it can be assigned the same material but have different part of the texture render. Or can UV maps of runtime-created meshed be altered?

avatar image Jaap Kreijkamp · Jan 15, 2010 at 08:39 AM 0
Share

You're right about the Resources thing, it's just that I did it wrong once with Shader.Find so I'm extra careful to ensure stuff is referred in the project. You can create $$anonymous$$eshes runtime including its UV maps. Look at the $$anonymous$$esh class for this.

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

No one has followed this question yet.

Related Questions

Why is uninitialized GameObject != null? 1 Answer

The name 'Joystick' does not denote a valid type ('not found') 2 Answers

Clone Selector 1 Answer

Change a Script Var of an Instantiated Object 1 Answer

Detect when instance has deleted 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