Abstract class question

Hi, im using polymorphism fro all my hitboxes, so they are derived from a Hitbox base class, but i dont want the user to be able to create an instance of Hitbox class, so i tried making it abstract

but im still able to create an instance, why? does it have something to do with that Hitbox inherits from Monobehaviour? what im doing wrong?

64204-22ss.jpg

(totally different class)

No, you can’t create an instance of an abstract class. If you try to attach a script with an abstract class to a gameobject, the Unity editor will show a popup message with this text:

Can’t add script behaviour
AbstractBase. The script class can’t
be abstract!

If you try to add this class from code (with AddComponent) you will see the same message in the console.

You said:

im still able to create an instance

How did you create an instance of that class? From what you posted in your question you only only try to create a variable of your Hitbox class, but not an instance.

Maybe i don’t fully understand your problem. If the class is abstract you can’t create an isntance. Not even with reflection, it’s impossible.