Combine Children Extented (sources to share)

At first, sorry for my english. My teachers were Japanese
:lol:

As it is known, combining of the objects using one material in one mesh, strongly raises productivity. For this purpose in Standard Assets Unity there is script Combine Children (further: the Combine)
In the course of my work, some additives to a standard script of the Combine were created. And I share it:

[V] Frame To Wait: how many frames on script start to wait before to make combining.
For example, you have an object containing one hundred more other objects which too contain childs. Prefab of internal objects, it is equipped by the Combine with own customisations. On start, all of them will be combined and we will receive less meshes, but all the same a heap. Why not to Combine them again?
We put “1” in this setting and in a following frame, after end childs is combined, we stick together new received meshes again and it is received 5 - 10 meshes instead of old hundreds.
[V] Combine On Start - the script will work on composition start (if it is activated, sure).
[V] Destroy After Optimized - to kill all initial objects. Cautiously! If on these objects have colliders, they too are deleted.
[V] Cast Shadow - created mesh will cast shadow.
[V] Receive Shadow - created mesh will accept shadow.
[V] Keep Layer - the created object will save the same layer, as for the initial object (on which the script is)

Well and, a bonus!
[V] Under the right button there lives Combine Now command. That allows to spend all combination directly in the Editor, to estimate changes and, or to cancel them, or to save in the Scene. That is - to avoid necessity combining on application start.

UPDATE : WinRT compatible version from Nidre

UPDATE : New command (“Save mesh as Asset”) added. Undo-Redo is supported now. Also, the script renamed to CombineChildrenExtended.cs

242514–8698–$combinechildren_962.cs (5.27 KB)
242514–69833–$CombineChildrenExtended.cs (6.13 KB)

Thanks for sharing.

Great!
I have made some customisations of my own to that script, but this is even better! :smile:

I have forgotten to explain one more command. By call of this command, there is a search and execution the Combine Children script on all children, except the object from which the command is started.

Thanks for this! The ability to combine in editor rather than at start gave me some much needed reduction in start time within one of my iphone apps.

Just a heads up for others interested in this script, it does cause a few problems in the iphone version. Namely the CallCombineOnAllChilds method. I think it has to do with how the array c is declared. I didn’t actually need that functionality, so I just commented out that whole method and everything works beautifully. Maybe someone with a little more iphone-specific knowledge can properly declare the array and regain that funcitonality :slight_smile:

I’ll check it tomorrow in iPhone. I thing, there is some .NET 2.0 incompatibility.

But, this is not an absolute method. Sometimes combined mesh is disappears. Be cary in Editor.

New version uploaded in the first post. A little bit improved.

i have a lot of meshes in the scene,although they are all in separate GO with some scripts attached. could
i use this script since it combines meshes, will i be able to use it as i am now? thanks!

Hi Neodrop,

This is a very cool script. Although i have lightmaps on my gameobject that have this script running and my objects totally disappear once the game is executed. I am not a programmer but just wanting to know if anyone has an explanation to why all my game object children meshes disappears and without lightmaps it works ok.

I saw a similar disappearance with using Unity’s Combine function on a laptop. This was displaying absolutely fine on my home PC, but on the laptop, certain precise chars were disappearing.

I later found that it was causd by my laptop’s GPU, which was badly interpreting some of the imported normals.

Try to put “calculate normals” in your FBX importer on your models, and set it to 60. It completely solved the problem for me.

Hi Nomad,

Thanks heaps for the info i tried doing what you said but it did not work :frowning: i may have to look around more and experiment. I am currently exporting from XSI but it seems like a bug so I will get Unity tech to look at it.

whoa… I just found this script, Thank you Neodrop! Another very useful script(as is Antares Vizio). The ability to combine in editor is MUCH APPRECIATED!

Holy crap - using this script just helped me a ton - Thanks for a great tool.

@shinja: You’ve probably moved on, but your objects are probably disappearing when using lightmaps because UVs are being changed when the new meshes are created on startup.

I’m guessing you can solve this by using this script’s awesome “Combine Now” feature. Combine your objects in the editor, and THEN do your lightmapping and things should be fine.

Trying to make this script work but when I try to attach it to an object it says that the filename does not match the class name… and it seems there is no class name definition in the script.
I am no C# programmer so I cannot solve this problem :expressionless:

By the way, Neodrop, I’ll be glad to help you with any project with a couple of models to pay back this precious script :slight_smile:

This is very old script. May be it’s is obsolete for Unity 3.0
In my Antares Project I have new working one. Take it from my signature.

Privet Neodrop,

when combining meshes would it be possible to recombine gameobjects/meshes on runtime? How much of a performance impact would that be? Too much to even think about it? I 'm wondering if it might be an option in an iPhone game to reduce draw calls with meshes that switch materials during gameplay? For example when collision happens collided objects change material, then, based on the material the object is added/removed/combined dynamically.

You can do it, if you will store source meshes somewhere and use it for recreating/restoring objects state.
I thing, mostly all will works fine in reltime (I often have used it in realtime). But in Unity 3.x.x we has a static dinamic butching and in most cases I don’t need self-combining anymore.

Thanks Neodrop!

Does this mean that I destroy the combined mesh, create a new combined mesh from other source object meshes and recombine these based on their shared material + doing the same for another material? I would like to switch materials of individual childs inside a combined mesh. It would start with one material+one combined mesh ( one draw call) and end with two combined meshes based on two materials ( 2 draw calls)? This is supposed to happen on the fly on a collision event in realtime?

According to the documentation dynamic batching makes sense only with objects below 300 vertices due to overhead, so only combining or using workaround with bones+mesh makes sense as solution (in my case I have more than 1000 vertices per object).

Thanks very much! It’s great.

so small, so sweet and so smart: a very useful script in case you want to speed up your game.

thanks a lot,

lars