8

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.

0

4 Answers 4

6

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).

Sign up to request clarification or add additional context in comments.

Comments

6

In my case, this error was caused by a reference to an old version of a class that used to derive from MonoBehaviour(in current version, it does not). All that I had to do was to remove it from the GameObject on the scene.

Comments

1

I was messing with adding a static class to a GameObject, then changed the capitalisation of it, then changed what it inherits etc. Finally I realised the reference to the script had "dropped off" the GameObject, notice how instead of the name of the script I just have (Script)?

Try removing the component

After removing my singleton I was good to go.

Comments

0

If you are using latest version (2020+) those days you don't need to attach static class to the GameObject. You can call it from anywhere. So just delete script from object.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.