> Does GameObject.Find() work on> inactive objects? If not, how do you> find and reference inactive objects.
GameObject.Find() is only useful (good) in small scenes. Best practice is to avoid using this for any scene with more than a handful of gameobjects (including children).
I find it is best practice to store a reference to every gameobject you create.
How do you keep track of your gameobjects? By name? UniqueGUID? By type?
You could use Dictionaries for this, sorting them by any way you desire.
By name or UniqueGUID & gameobject
Dictionary allObjects;
string myGUID = Guid.NewGuid().ToString();//By Unique GUID
By position & script type
public static Dictionary allTiles = new Dictionary(); //Collection of all Tile GameObjects via Tile.cs script
By name/uniqueID & script type
public static Dictionary allGameWorldObjects = new Dictionary(); //Collection of all GameWorldObjects
public static Dictionary allPlayerObjects = new Dictionary(); //Collection of all PlayerObjects
All objects in array
Gameobject[] AllObjects;
In a list by class
List allGameWorldObjects ; //Holds all GameWorldObjects, PlayerCharacters, & Containers
public class GameWorldObject {}
public class PlayerCharacter : GameWorldObject { }
public class Container : GameWorldObject { }
In a list by gameobject
List allPlayerObjects;
List allGameWorldObjects ;
↧