- Home /
Can a GameObject inside of an array be made "accessible" from the editor?
Right now I'm developing a game that requires enemies to spawn at specific times.
To simplify this process, I have sort of a "spawning manifest", which contains 3 different public arrays. The first lets me choose a prefab, the second lets me pick what time each enemy is spawned, and the third tells it where to spawn.
However, enemies of all different types will need to be spawned (and they have numerous variables, such as firing rate, movement speed, etc.). Will I need to make a prefab of every tiny variation, or is there some way to access (in the editor) a GameObject's components/values while it is displayed inside of an array?
For instance, in the Inspector I unfold the "Enemies" array, add one to the list, and I can see all of its editable values much like if I selected the prefab directly?
If not, this doesn't bode well and I'll have to scrap my entire spawning system, and unfortunately I don't know what else to do in its stead except place every enemy by hand.
Answer by assaf.mendelson · Aug 16, 2011 at 05:16 AM
The easiest way to do this is to create a custom inspector. you should start with: http://unity3d.com/support/documentation/Components/gui-ExtendingEditor.html here is an example of building custom arrays: http://answers.unity3d.com/questions/26207/how-can-i-recreate-the-array-inspector-element-for.html what you would need to do is add some stuff to expand each array element in a similar manner.
I've been scared of trying to extend the editor so far. :P It seems fairly complicated. I'll consider it though.
Answer by Waz · Aug 16, 2011 at 05:26 AM
Sounds like your structure dependencies are backwards, since you don't want the variables in the prefab GameObject, yet you have them there. I would suggest that you move those variables you mention to an EnemyData class that is just a structure of the variables. You then have a single array of these. When an object is spawned, the prefab is instantiated, and a data
variable that replaces those variables is set to the one in the array.
Yeah, I'm still trying to learn as I go and I'm finding more and more that the less I plan, the more stumbling blocks I hit on the way, so I'm trying to make everything as easily modifiable as possible. I thought I was being proactive for my spawner but it clearly has its shortco$$anonymous$$gs. I suppose I could do what you say, and then use Send$$anonymous$$essage to the instantiated objects to inform their statistics (I have to use something general because all the different enemy types are so different that they use different AI scripts, though I could give them all similarly-named functions so they can receive generic Send$$anonymous$$essage orders). Not sure if I'm muddling your suggestion though.
Your answer
Follow this Question
Related Questions
Custom Inspector: Targets & GameObjects 1 Answer
Insert new custom class element with _default_ values to a SerializedProperty array? 1 Answer
Prefab not loading in data from Inspector 1 Answer
Can one specify the parent of a gameobject in an array? 2 Answers
How to set to game objects's position from 2 different game objects arrays equal to each other? 0 Answers