Creating a prefab of a GO that uses a script that inherits another class that inherits Monobehaviour

Hey! I am working on a moba-like project and currently I got started to work on something that will make it easier in future, kinda like layered architecture in web dev.

UnitInfo.cs, where i hold general information

public abstract class UnitInfo : MonoBehaviour
{
...
}

And
DummyUnit.cs, where i hold the specific details and functions.

public class DummyUnit : UnitInfo
{
...
}

So ideally I give my GameObject “DummyUnit.cs” script, But since that script doesn’t inherit MonoBehaviour directly, unity doesn’t allow me to create a prefab of the GameObject.
6692488--767791--upload_2021-1-6_3-44-33.png

I have seen on my research that some people keep all unit types in one script which is not ideal and I am not even sure how it could work. Also would cause problems when there is too many units.

How can I create a prefab for this object, with an organized layers of architectury.

I am pretty new to unity, so any advice is appreciated. Thank you!

Edit: The process and the error.

[ATTACH=full]768061[/ATTACH[/ATTACH]

6692488--767788--upload_2021-1-6_3-44-14.png

You just showed a screenshot of your DummyUnit component on a GameObject. That part is obviously working. DummyUnity absolutely derives from MonoBehaviour. So what are you seeing when you try to make a prefab? It should work fine.

In any case I would advise against the use of inheritance for this. You don’t gain much from it. Make UnitInfo one component, and make DummyUnit a separate component.

1 Like

What do you mean that Unity doesn’t let you create a prefab? Does it give you an error message when you try?

What you are trying to do should work.

1 Like

@bobisgod234 @PraetorBlue Thanks for replies, I am sorry for the late reply I just woke up.

Unity gives an error telling that the prefabs scripts should derive from Monobehaviour, and says that this’is not allowed.
I will upload screenshots in a few minutes.

6694189--768058--upload_2021-1-6_15-46-13.png

6694189--768058--upload_2021-1-6_15-46-13.png