Search code examples
unity-game-engine

Error Attaching Unity Script to gameObject


I got an error when I try to attach my script to a gameObject.

'EnemyBehaviour' is missing the class attribute 'ExtensionOfNativeClass'!

Another times, I got:

Can't add script behaviour CallbackExecutor. The script needs to derive from Monobehaviour!

I have made sure my class derives from MonoBehaviour.


Solution

  • To solve your issue:

    1. Fix all compiler errors of this script and all other scripts. Compile errors in other scripts can cause the Unity Editor not be able to analyze your current script. Go to your code in visual studio and build the entire solution. Fix all compiler errors before going back to Unity Editor.

    2. Make sure the class inside your script is inherited from MonoBehaviour. This is the obvious one but surprisingly, sometimes, you still get this message even if your class is inherited from MonoBehaviour! If so, you should fix all compiler errors in other scripts (Read item #1).

    3. Make sure the class name is exactly the same as the script name (even the same capitalization).

    I solved mine by fixing a compiler error in a different script (item #1) and fixing a typo in my script file name (item #3).