Assigning script type variables in Unity editor

Ok, so here’s what I’m trying to do. For the characters in my game I am trying to set up a generic system for assigning abilities to lots of characters in the game. So here’s what I’m trying to do:

In the generic character class that all the characters in my game will use I have a public variable of type AbiltiyBase (which is a script). From there I want to be able to make any ability that crosses my mind and make them inherit from this class. I was hoping to be able to drag the script that inherit from type AbilityBase and drop them on the little opening that shows up int he editor that says None(Ability Base) so I can assign abilities in the editor on a character basis. Is this possible? Well I try and drag and drop already and it’s not working. Am I doing something wrong? Please help!

It’s totally possible, as long as AbilityBase is serialisable.

How do I make AbilityBase serialisable? What does that mean in this context for that matter?

You said that AbilityBase is a script, by which I assume you mean it inherits from MonoBehaviour in some way (if it shows ‘none’ in the inspector, it must).

If that’s true, then it’s already serializable.

You don’t drag the script into the field though. You drag the script onto a gameobject you want it attached to, then you drag the gameobject that it’s attached to onto the field.

NOTE, all this does is let you reference the script attached to the gameobject it’s attached to. If you’re just attempting to add abilities to a GameObject… you just add it, you don’t need this field.

1 Like

Sounds like a job for ScriptableObject (in combination with custom assets)