Array of Monobehaviour?

Is it possible to do this? I have created a monobehaviour, “Unit”, that details all the necessary attributes that “units” have (health, mana, etc…) as well as a list of “abilities”. I have created a class, Ability that I can use to create specific abilities. Is there a way, through the editor to fill the array with specific abilities? In the editor there is an array of “Abilities” but it does not let me create new instances right from the inspector panel.

Lets see how you creted your class (example), and I’ll see if I can help.

You have to set the length of the array in the inspector first. If you type in 3, it will create 3 rows where you can put your Ability instances. Though it might be easier for you to just add all the abilities to the Unit as separate components and then get them all in the Unit’s start function by calling GetComponent().

For the Unit component, this is basically it:

For the ability, it’s basically the same thing. Just another MonoBehaviour with some properties

It correctly shows in the inspector an array of abilities, and I can edit the length of the array. What I want to do, is “instantiate” several abilities, and be able to edit them while in the inspector. Does that make more sense?

If you just want properties don’t inherit from MonoBehaviour, just use a plain old class and annotate it with System.Serializable. If you want to actually create GameObjects with the attached Ability then instantiate them separately.

Changing it with System.Serializeable allows me to edit each ability’s properties, but what i wanted was to create the abstract class “Ability”, then hard-code what each ability does (like a magical arrow would create an instance of an arrow, a heal would change the health on X units within range, etc…). So I would create this hierarchy:
Ability → Magic Arrow
→ Group Heal (heal x units within range)
→ Raise Dead (create some prefabs of skeleton minions, add on a buff that kills them when its over)
And then I could go into the editor, and pick and choose which abilities to add so I could have an undead minion that could raise dead and heal his minions, and then add some other abilities to the hero etc…

The best solution that I’ve come up with, is to add a massive enum where I list each ability, pick and choose which ability I want with an array of enum in the editor, then the game would assign each ability to the array through the enum. But this seems really dirty and hacky to me, and just a hassle to keep up with. Anybody got any other ideas?

After some thought, it may be better to add abilities as components.
When the game starts, will the gameobject know ALL the components it has? So I can, on the Wake of one component gather all components and determine which abilities it has?

EDIT: For the time being, I’m making each ability a monobehaviour (they all inherit "Ability"s properties). I add each ability as a component, and on “Start” of “Unit” (which all units in my game have) it searches for all abilities using “GetComponents()”. This seems to do the trick, and allows me to edit all the abilities within the editor. Thanks!