Always use MonoBehavior for custom classes ?

Hello Everyone,

I’m trying to do a customEditor for my asset and i have to define propertyDrawer for few custom classes. Some of them are abstract class and serialization doesn’t work.

After few search on Google it looks like i have two options :
-Create a custome serialisation for this classe (ScriptableObject)
-Inherit my custom class from MonoBehavior

it looks like everything is simple when inherited from MonoBehavior but I need to use constructor in my customs classes to initiate them in other script.

Am i missing something and should i always used monoBehavior child ?
Or ScriptableObject is the best solution for inheritance / polymorphism ?

Thanks for your help.

@tribaleur there’s really no best way of doing things

  • If the class itself has to be connected to a game object extending MonoBehavior would be ur best approach and using the Instantiate and/or adding a function that gives you you’re custom parameters instead of you’re constructor would be the best way to go
  • While if you wish to have an object in you’re assets folder to storing data using the editor and getting basic information for example using ScritpableObject would be the best approach.

on a side note a class that you want shown in the editor needs to be serializable which is possible by adding the tag [System.serializable] so whenever it’s public in a game object you get to see it inside the editor that might help if case you’re ever wondering.

[System.serializable]
public class Test
{
}