How to instantiate unique prefabs

UPDATE: !!! NO MATERIALS !!!

I’ve an prefab (object with childs on it). That childs could be manipulated, let’s say placing a cheesecake on them. That’s my problem. The instantiating (clone) works nice, but when I manipulate a clone, sure the next one get the manipulation.

Whole thing will not work in future as long as I need really unique prefabs. Best would be when the cloned and the childs get kind of + number like clone 1(child1) - > next instantiate clone 2(child).

Every instantiate it must be a unique new prefab. Any ideas in c?

UPDATE: !!! NO MATERIALS !!!

The problem is material as materials are shared by all the prefabs.

Material colors are not my problem. Later the prefab get datas save/load on it. So I need to call directly adressed.

You need cloned materials, like material0, material1, material2, and so forth. Clones of object can all be named same. Just duplicate the material too, and then you can change fine. Hope this helps.

okok, forget materials…

Question: How to add “something” to an instantiated prefab, to make ANY new instantiated copy of this prefam unique?

Example:

original
original1 (copy1)
original2 (copy2)
original3 (copy3)

And there is no materials… No, never… I hate materials… Materials are bad!.. Unity don’t have materials… lol

Alex,
I am not getting your question. Could you please explain it?

He wants to instantiate prefabs, each with their own unique name.

Probably a more effective way of doing this however, you could attach a script which sets the name of the object followed by a number which is taken from an empty game object containing a variable which gets increased each time the object is instantiated.

Example:

When you instantiate your prefabs, call the count function inside the empty game object

counter (attached to empty game object):

static var count : int;

function count () {
	
	count += 1;

}

In the update function of a script attached to the game object being instantiated:

function Update () {

	gameObject.name = "original" + scriptName.count;

}

Attach this to the prefab. You can alter it to get rid of (Clone).

using UnityEngine;
using System.Collections;

public class UniqueName : MonoBehaviour {
	
	static int num;
	
	void Awake () {
		
		name += num.ToString ();
		++num;
		
	}
	
}

Great! Thanky people… I’ll could go on to work with this… Daniel: Thank’s for the c# edit :wink:

Manipulating an instance created with Instantiate does not effect the other instances of the same prefab unless you are doing something strange that makes it do so (using static variables where you shouldn’t be, not using instantiate properly, etc).

If you are addressing objects by name … don’t. It might be great for Unity’s quickStart guides but its generally not a good idea. When you instantiate something you get a reference to it… keep it!

Also (not so much for the OP), when you address material you are effectively cloning the material. You need to explicitly access sharedMaterial to affect all the instaces.

Attached is a silly little unity project which instantiates objects with children then moves the children all independently of each other despite the fact they all have the same name.

976170–36111–$SillyLittleExample.unitypackage (13.5 KB)

Everything works fine now (also my headache is still working fine… dam).

I swap from mother prefab to child prefab now. It’s better than rubics cube. The only problem so far was to prevent to instantiate from the directional copy, so when the last instantiated prefab was manipulated, for sure tzhe clone would also be. The whole thing works now for me. I also attached Mr. Quicks anticlone, and it does counting upwards. Without headache I would dance in my room. This part of my game is the hardest I bet. Never thought before it would be THAT hard… 8)

Sure I wanna say thank you to ALL helping hands again.