Can't apply script/component to Enemy prefab

Topic. I get this error

“Can’t add script component because” the script class cannot be found."

I Googled the error, I am not sure what I am doing wrong as I am following the tutorial.

Which component are you trying to add?
Paste in the script for that component and we’ll take a look.

I find when that error happens, it’s often when you’ve changed the name of the script and left the original class name or vice versa.

I feel this error often happens when i make a script without Start() and Update(),
adding them back in fixes things.

Or just making some random change to the script in question (which does compile)
save, go to unity and back in the script to revert the change and save again.

That are 2 things that solved it for me in the past anyway.

That should have little to do with it. To be able to add the component to a GameObject, it must be a MonoBehaviour class, and the name of the class must match the name of the file (Case Sensitive!). The class can be completely empty, and it would still be addable to the class.

It also must have compiled without errors.

Hi Brian,

I agree, it shouldnt.

I always copy/paste names if i change them, so that never was a problem,
just sometimes Unity bugged and did not “recognise” the script,
even after i made some changes to force it to recompile.

Then i just remembered that for the checkbox to turn a script on/off in the editor to appear,
the script needed to contain a Start()/Update()
So i tried adding those back in, and then i could add it to the GameObject.

I did forget to say, afterwards i could remove Start()/Update() again and it kept working.

This topic was automatically closed 20 days after the last reply. New replies are no longer allowed.

Privacy & Terms