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 ThumbStorm · Oct 13, 2010 at 09:23 PM · instantiatemeshcombine

Combining meshes at runtime

I feel like this is asking a lot but I'm completely lost on the subject. I have a script which instantiates small pieces to create a racetrack at the beginning of each level. It works fine but I need to reduce the draw calls. I have an empty game object named StartingPoint with the Create track script on it. There are half pipes, flat, and U shaped pieces of track. The pipes share one texture, flat has another, and U has one as well. Once all of the pieces are created I run Mesh.CombineMeshes in a function called CombineMesh. The Problem is the CombineMesh sets all of the created gameObjects to inactive because of this line(meshFilters[i].gameObject.active = false;) When i change it to true all of the gameObjects are active but not combined. I've looked through the docs, forums and answers but just can't grasp how to achieve this.
any help would be awesome! example code:

var PipeStraight : GameObject; var PipeTurnLeft : GameObject; var PipeTurnRight : GameObject; var UStraight : GameObject; var UTurnLeft : GameObject; var UTurnRight : GameObject; var nextPoint : GameObject; //empty gameoject that moves to next instantiation point//

function Awake() {

 nextPoint.transform.position = Vector3(0, 0, 0); 
 nextPoint.transform.rotation = Quaternion.identity; 
 trackNumber = 1;//get variable from mainscript// 

}

function Start() { CreateTrack(trackNumber);
}

function CreateTrack(trackNumber : int) {

if (trackNumber == 1) {

var Piece1 = Instantiate(Lpipe90_1200, transform.position, transform.rotation); Piece1.transform.parent = transform; NextPointMove("Lpipe90_1200");

var Piece2 = Instantiate(Lpipe90_1200, nextPoint.transform.position, nextPoint.transform.rotation); Piece2.transform.parent = transform; NextPointMove("Lpipe90_1200");

var Piece3 = Instantiate(Lpipe90_1200, nextPoint.transform.position, nextPoint.transform.rotation); Piece3.transform.parent = transform; NextPointMove("Lpipe90_1200");

var Piece4 = Instantiate(Lpipe90_1200, nextPoint.transform.position, nextPoint.transform.rotation); Piece4.transform.parent = transform; NextPointMove("Lpipe90_1200");
} CombineMesh();

}

function NextPointMove(moveName : String) {

 if (moveName == "PipeStraight") {
     nextPoint.transform.Translate(0, 0, -360);
 }

 if (moveName == "PipeTurnLeft") {
     nextPoint.transform.Translate(0, 0, -360);
 }

 if (moveName == "PipeTurnRight") {
     nextPoint.transform.Translate(0, 0, -360);
 }

 if (moveName == "UTurnLeft") {
     nextPoint.transform.Translate(0, 0, -360);
 }

 if (moveName == "UTurnRight") {
     nextPoint.transform.Translate(0, 0, -360);
 }

if (moveName == "UStaight") { nextPoint.transform.Translate(0, 0, -360); } }

function CombineMesh () { var meshFilters = GetComponentsInChildren(MeshFilter); var combine : CombineInstance[] = new CombineInstance[meshFilters.length]; for ( i = 0; i < meshFilters.length; i++){ combine[i].mesh = meshFilters[i].sharedMesh; combine[i].transform = meshFilters[i].transform.localToWorldMatrix; meshFilters[i].gameObject.active = false; } transform.GetComponent(MeshFilter).mesh = new Mesh(); transform.GetComponent(MeshFilter).mesh.CombineMeshes(combine); transform.gameObject.active = true; }

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

Answer by Peter G · Oct 13, 2010 at 10:59 PM

I would recommend looking at all these scripts.

http://www.unifycommunity.com/wiki/index.php?title=MeshMerger

http://www.unifycommunity.com/wiki/index.php?title=CombineSkinnedMeshes

http://www.unifycommunity.com/wiki/index.php?title=SkinMeshCombineUtility

The first one is probably your best bet.

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 ThumbStorm · Oct 14, 2010 at 12:10 AM 0
Share

I looked at that but just don't understand it.

avatar image konsnos · Jun 24, 2014 at 12:27 PM 0
Share

I tried to use all of them but failed miserably. None seems to work.

avatar image
0

Answer by yoyo · Dec 12, 2010 at 07:56 AM

You could consider procedurally generating the whole mesh, rather than creating a multitude of game objects. Look at the docs for Mesh, including how to create one from scratch.

I procedurally create a mesh to "draw" a trail on the ground behind a vehicle -- a similar technique could be used to generate a track. Rather than instantiating each of your ready made track pieces, you could use the Meshes in the ready made pieces as templates, but copy the data into one large new Mesh. You would need to transform the points as you copy the data, since you no longer have a separate transform per track piece.

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

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

Fastest way to instantiate thousands of objects at runtime? 1 Answer

Checking if object intersects? 1 Answer

How do I fix this error code: BCE0023: No appropriate version of 'UnityEngine.Object.Instantiate' for the argument list '(System.Collections.Generic.List., UnityEngine.Vector3, UnityEngine.Quaternion)' was found. 2 Answers

Projectile instantiation positioning is off. 3 Answers

Instantiate ground/enemies 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