Reputation: 1389
Consider a cube.Initially the cube is converted to prefabs by dragging into the project window and deleted from the hierarchy.Now this prefab is getting Instantiated.So when it gets instantiated a couple of times, all the instantiated gameobjects will have the name Cube(Clone).Is there a way to identify these clones like any unique features.
Upvotes: 0
Views: 478
Reputation: 7515
If you want to identify your objects through something else than the name directly, you can always add a field or property to these objects and display it in the editor associated (or the default one.)
That value would be populated by the constructor if auto-generated, or the Clone method if you want to have a control over it.
Upvotes: 1
Reputation: 51
You can do this.
Example:
public class MyClass : MonoBehaviour
{
[SerializeField]
GameObject myPrefab;
void Start()
{
GameObject g = null;
for(int i = 0; i < 5; i++)
{
g = GameObject.Instantiate(myPrefab);
g.name = "MyPrefab_" + (i+i);
}
}
}
This should instantiate 5 game objects named:
Upvotes: 2
Reputation: 1712
several ways. clicking them in the inspector will show them in the scene view and vice versa, but you could also do it via a script to increment some sort of ID, this method will go in place of your instantiation.
int id = 0;
for ( int i = 0; i<5; i++)
{
GameObject yourob = Instantiate(obj) as GameObject;
yourob.gameObject.name = "Object " + id;
id++;
}
this will get rid of the clone name convention and leave you with
Object 0
- Object 4
note: you can change the string Object
to whatever you want.
Upvotes: 3