Issue with public parameter in component-based design...

My intended pattern for my AI system was that a component OverMind would be configured on a prefab and instantiated using the prefab’s saved parameters.

So you might have one that’s set up to make sword guys and one that’s set up to make bow guys and they both have a unique model spit out different guys but all you have to do is instantiate either to set a big chain of events into motion.

One of the parameters I need is a script, it’s base class is BaseEntity. It is not abstract or anything, it’s just a regular class with some virtual methods overridden. I know for a fact scripts can be editor fields, I’ve done it before, but never with an object-oriented design.

public class OverMind : MonoBehaviour
{
    public int MaxMembers;
    public int FamilySize;
    public BaseEntity HostedEntity;
    public GameObject EntityBody;

Why doesn’t HostedEntity show up as a field in the editor? My alternative is to use an initialization method, but I don’t want to- this is the layer of my structure I wanted to be component-based.

In that scenario the OverMind script would be added as a component and in its Awake method it would disable itself, then an Initialize method you must call and pass parameters would “construct” the behavior and enable it allowing its Unity loops to start doing stuff.

Would it work if I made BaseEntity an Interface? I don’t want to, since it does have default methods (like a gravity method, for example).

After some reading I sorta/kinda get it, can’t serialize that class, so it doesn’t show up in the inspector. Monobehaviours show up no problem. I think I could get it in there with a PropertyDrawer but since I’m not interested in learning that whole thing right now I’ll just do both things, have prefab parameters and require a follow-up enabling call providing that one class reference.

Did you already figure this out? If not the following should work.

goto your BaseEntity class definition and make it serializable by adding in the attribute [ ]

[System.Serializable]
class BaseEntity : MonoBehaviour {
}

All public methods should show up in the inspector and you can make private ones appear with

[SerializeField]
private int myVar;

That is interesting and I did try it, but it doesn’t result in a field where you could drop a child class of type Base, which is what I need. It only results in fields for the class’ variables.

I think I need to use an Interface.

Edit: yeah it an Interface doesn’t show up either.

I just have like, Animal : Dog, Cat, Bird

I want to be able to have a prefab with a reference to Dog, Cat, Bird, chosen. Idk.