CombineChildren in EditMode?

This doesn’t appear to work.

I have a script that reads a text file and uses this information to assemble a bunch of primitives into an aggregate game object.

I’d like to be able to save this new object as a prefab, and I thought I could execute the script in EditMode.

Everything runs fine in EditMode, except that CombineChildren doesn’t execute. It is attached to appropriate parent objects.

(all the same code runs as desired in runtime/game mode)

Any ideas?

Thanks

Are you using a editor script or a normal script with ExecuteInEditMode enabled? Any chance you can post the script?

It’s an OnGUI script I originally wrote to assemble an object out of sphere primitives in game, but I wanted to try it offline to see if I could generate the assemblies of spheres and save them as prefabs.

All the code does is read a text file of 3D coordinates and places a sphere at each X,Y,Z that’s read from the text file. Along the way, I create a parent, attach CombineChildren, and parent the next N spheres read from text into that parent object.

import System;
import System.IO;
import System.Text.RegularExpressions;

@script ExecuteInEditMode()

//#pragma strict

//var textAsset : TextAsset = Resources.Load(inputPDB);

var textAsset : TextAsset;

var Carbon : GameObject;
var Nitrogen : GameObject;
var Oxygen : GameObject;

var primCylinder : GameObject;


var blobCount : int = 0;
var totalblobs : int = 0;
var serial = new int[8000];
var vec = new Vector3[8000];
var vecSum : Vector3;
var blob = new int[8000];

var cradius : float;

var blobType = new Hashtable();
var primblob = new Hashtable();


var tempTime : float;
static var sphereRadius : float;


var currentgroupingGO : GameObject;
var assembly : GameObject;
var sphere : GameObject;
var currentgrouping : String = "A";
var grouping: String = "A";
	
var groupingCount = 0;
var groupingName = new Array();



function Awake() {


	blobType["A  "] = 1;
	blobType["B   "] = 2;
	blobType["C   "] = 3;
	blobType["D   "] = 4;
	
	primblob[1] = A;
	primblob[2] = B;
	primblob[3] = C;
	primblob[4] = D;
	
	
}



function OnGUI() {

	if (GUI.Button(Rect(20,20,60,60),"BUILD"))
	{
		if (textAsset == null) return;

		reader = new StringReader(textAsset.text);
		line = reader.ReadLine();
		groupingCount = 0;

		while (line != null)
		{
			if (line != null  line.Substring(0,3) == "END") 
			{
				
				groupingCount++;
				groupingName[groupingCount] = currentgrouping + "-grouping";
				currentgroupingGO = new GameObject(groupingName[groupingCount]);
				currentgroupingGO.AddComponent("CombineChildren");

				for (var n =1; n < blobCount; n++)
				{					
					sphere = Instantiate(primblob[blob[n]],vec[n],Quaternion.identity);
					sphere.transform.parent = currentgroupingGO.transform;
				}
				totalblobs += blobCount;
				blobCount = 0;
			}
			

			if(line.Substring(0,4) == "blob")
			{
				var elem = line.Substring(13,4);
				if (blobType[elem])
				{
					blobCount++;
					blob[blobCount] = blobType[elem];
					grouping = line.Substring(21,1);
					
vec[blobCount] = Vector3(float.Parse(line.Substring(30,8)),float.Parse(line.Substring(38,8)),float.Parse(line.Substring(46,8)));
					
					vecSum += vec[blobCount];
				}
			}
			
			line = reader.ReadLine();
			
			currentgrouping = grouping;
			
			if (line != null  line.Substring(0,5)== "MODEL"  line.Substring(13,1)=="2")
			{
				line = null;
			}
			
		}
		
		assembly = new GameObject("assembly");
		COM = vecSum/totalblobs;
		assembly.transform.position = COM;

		for(var igrouping = 1;igrouping<=groupingCount;igrouping++)
		{
			GameObject.Find(groupingName[igrouping]).transform.parent = assembly.transform;
		}

		CameraTransZoom.mainCameraTarget = assembly.transform;
		SmoothLookAt.target = assembly.transform;

	}
}

CombineChildren is actually a script and unlike your script, it doesn’t execute in edit mode. However, another approach you could use is to call Mesh.CombineMeshes from your script in response to the button click.

Thank you, kindly.