Naming Instantiated Objects
D41 #PanicRoom
R2D11 #100DaysOfCode
R2D06 #100DaysOfGameDev
I was having trouble getting Wall Tile manipulation to work and figured I would use the Unity GUI to aid me by directly clicking on the Game Objects in the area of the game I was having trouble working with. This led me to realize that all my hundreds of cloned Prefabs were being named after the file name with a number appended and there was absolutely no way for me to tell them apart by name. Of course, this made sense upon seeing, however this would not do at all. I need to be able to troubleshoot problems easily and this was a huge hindrance.
I then had to stop what I was working on and go into research mode to discover the proper way to go about naming my Game Objects with unique identifiers right when I Instantiate them. This actually isn’t all that difficult and, once you do it, it is really easy. The key is in the Object.name field which is easily assignable via any convention you wish. You treat it like any other String and it makes naming things for later (easy) identification a breeze.
I used it to give my instantiated Wall Tiles a name utilizing their orientation (Vertical or Horizontal) and their [x, y] grid assignment. Now when I look through my in-game list of hundreds of tiles it is a snap to locate the one I want and see just where it is and what it is doing in my game.