- Home /
Can you have multiple MonoBehaviors in the same script file?
I made a C# file with three MonoBehaviours in it: a base class and two that inherit from the base. When I tried to attach one to a game object in the Editor, the only one that appeared in the list of components was the base class. When I created a separate C# file for each of the child classes, then they appeared in the components list.
It's not a big deal. I'm just wondering if it's possible to have multiple MonoBehaviours in the same C# file for convenience.
Answer by donutLaserDev · May 18, 2018 at 10:23 AM
Well, you can definitely create mulitple monobehaviours in the same file, but when you add the file to the game object, only the top-most behavior in the file will show up in the Inspector.
Generally, nobody makes multiple monobehaviours in the same file. You have to always create them in the separate files to be able to use them.
Your answer
Follow this Question
Related Questions
Enabling multiple Monobehaviour Components in a game object 1 Answer
Multiple Cars not working 1 Answer
Distribute terrain in zones 3 Answers
Disabling A Script on a GameObject From a Different Script 2 Answers
Adding scripts to items in a list 1 Answer