How to scale an object clone to fit a cube

Hi everyone,
I have in my scene an empty gameobject that spawn random modele of different scale.I want the clone to fit in the empty gameobject.
i try to scale the object in blender but as i have a huge list of object it’s a real pain in the *ss to make them one at a time.
Can someone help?
much love and respect to this amazing community :slight_smile:

I’m still unclear about the nature of an ideal solution. Note that an empty game object does not have a size, so I’m unsure what you mean by “fit in the empty gameobject”. So I’ll toss something out there and you can give feedback as a way to figure out what you need. The following script would need to be attached to items that you clone. The variable ‘emptySize’ is the size you want to fit into and needs to be set in the Inspector. For example, if you want to fit into a space of (1x1x1), then you would set this value to 1.0.

#pragma strict

var emptySize = 1.0;

function Start() {
	var mf = GetComponent(MeshFilter);
	if (mf != null) {
		var bounds = mf.mesh.bounds;
		var max = bounds.extents.x;
		if (max < bounds.extents.y) 
			max = bounds.extents.y;
		if (max < bounds.extents.z)
			max = bounds.extents.z;
		var scale = (emptySize * 0.5) / max;
		transform.localScale = Vector3(scale, scale, scale);

This is a runtime solution. That is at the time each object is Instantiated while the game is running, it resizes the objects.

thanks a lot for your answers!!
i’ve used robertbu’s code because i can read and (almost)understand javascript.
it work in a different way than the one i tought and it improve the scene. so thank a lot
i manage to use it in a different way by attaching the script to the clone when it spawn.but
(because there is alway a but) i’ had a script that make the object turn around itself and i can’t add the 2 component at the same time. i think i am pretty close but i cant manage.
here is the main script in the scene

 var spawnlist : GameObject[];
 var oscChannel : int;
 private var actu: int= 0;
 private var toload: int= 0;
 private var rotactu: int= 90;
 var tempo: int= 0;
 private var obj : GameObject;
 function Start () {
 	Instantiate (spawnlist[toload], transform.position, transform.rotation).AddComponent("holo_rotate").transform.tag = "holo";


 function Update () {

	var n = OSCReceiver.messages[oscChannel];
	actu = actu+1;
	toload = Random.Range(0, spawnlist.Length);
	obj = GameObject.FindWithTag("holo");
		var rotate = false;
		if (Input.GetKeyDown(KeyCode.A)) {
			//Destroy (GameObject.FindWithTag("holo"));
			Instantiate (spawnlist[toload], transform.position, transform.rotation).AddComponent("holo_rotate").transform.tag = "holo";


when i try to add component at the same in the if loop only the first component is added. and when i add it outside my clone get a bunch of it since its the update function.
i try another if loop but it hasn’t work.

the final look of the scene is various object rotating in the middle of the screen.(wich seem pretty easy at start)

can you give me a hint?