- Home /
Do not extend MonoBehavior
Hi,
I'm wondering if it's possible to remove MonoBehavior from unity scripts? They extend MonoBehavior by default, but I have a script which I don't want it on. (I'm using js).
Answer by Mike 3 · Apr 20, 2011 at 03:05 AM
You have to declare the class explicitly:
class MyClass
{
//code here
}
But don't forget: Js have the same rules as C# ;). The filename have to match the classname if you inherit from $$anonymous$$onoBehaviour and if you want to attach it as component. "normal" classes can be packed into any script file but if a class have a specific task and a moderate size it should have it's own file just for keeping the project clean.
@Bunny83: the rules aren't actually quite the same. In JS, the script is always automatically a class that inherits from $$anonymous$$onoBehaviour, so you can call it whatever you want, and any additional classes in the script don't have to match the file name.
Quite, yes. You don't have to put the class construct around the class, but if you do it have to match the file name in order to be that class (if you inherit from $$anonymous$$onoBehaviour). You're right that if you name the class differently, Unity creates an empty class with the file name anyway. That's actually what i meant.
Your answer
![](https://koobas.hobune.stream/wayback/20220613123934im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Remove trees dynamically - stuck with collider 3 Answers
InvalidOperationException: The list was modified. 1 Answer
Removing objects from an array 2 Answers
Clear whole list 0 Answers
MissingReference after removing component from gameObject 0 Answers