(I figured out the answer as I was typing the question. Rather than deleting it, I decided to post this for reference to anybody else wondering, because it wasn’t immediately obvious to me.)
Is there a way to give a name to instantiated objects (for debug purposes more than anything)? By default, instantiated GameObjects show up as “PrefabName(Clone)” (in the hierarchy) and “PrefabName(Clone)(UnityEngine.GameObjects)” (in the debugger). I’d like to the instance to get a custom name, very much like debuggers tend to use the ToString() method to describe runtime objects being debuged.
You can set the name of the object as soon as you instantiate it; you don’t need a separate script. Just use the return from Instantiate() to get a reference to the new object and change the game object’s name component there.
The simple answer to this is to set gameObject.Name to whatever string is desired in the Start() method of the script that’s attached to the prefab. Might seem obvious, but it wasn’t to me at first. For example:
public class Spot : MonoBehavior
{
private void Start()
{
gameObject.name = "Spot at [" + this.Col + ", " + this.Row + "]";
}
I might be a noob so please apologize. I came across this post in search of a way of naming a bunch of instantiated tiles on map generation grid thingy I’m making. Anyway, I noticed all instantiated objects have the “(Clone)” suffix attached to the Prefab name immediately after creation, which in itself creates a unique circumstance. At the moment of the instantiation, it is currently the only prefab with the (Clone) suffix available, so i made a
" public GameObject tempTile; " to go along with my
" public GameObject TilaA; " and my
" public GameObject TileB; " (I’m making a chess board kind of setup), and then immediately after the instantiation i ran
" tempTile = GameObject.Find(TileA.name + “(Clone)”); " or TileB for the alternative. Now with the temporary reference of the newly cloned tile, I simply used the method
" tempTile.name = “whatever”; " (I actually used this => ( “[ X: " + xPos + " | Z: " + zPos + " | AorB ]” ) which I’m also probably making a very terrible use of the string engine instead of creating an array, but I’m trying here!). The explicit reference to the newly made object seemed to clean up any issues… for now…