- Home /
I changed the name of some scripts and now I get a warning message but scripts run fine
I changed the name of several C# scripts in my project. I made sure to change the class names in the file AND the name of the .cs files themselves to match. Running the project now works fine, but I get several console warnings logged saying "The referenced script on this Behaviour is missing!".
Does anyone know how I might resolve this, or where I might look? Double-clicking on the warning does not do anything.
Thanks!
Answer by calmcarrots · May 25, 2014 at 04:49 AM
First, find the object where the component is missing. When you get this error, that means a component (such as a script) is missing and Unity cannot locate it. Once you find the object that is missing your script, delete that component and replace it with the script you want.
For example, let's say that you had a PlayerController.cs
script attached to your player object. Then you go and change that script to the name: PlayerMovement.cs
. The player object will not contain a PlayerController.cs
because it does not exist anymore. To fix that, go and click on the player object and add the new script. Your problem should be fixed.
Or, ins$$anonymous$$d of deleting and re-adding the script component; can click on the "none(missing)" in the component and select the renamed script. I think maybe it might remember the old public variable settings (untested.)
Then note: to see the problem, go to a scene where some object was using one of your renamed scripts. The object will now just sit there, doing nothing.
No, I'm pretty sure it was a Unity bug. Basically, don't change the name of your scripts once you're using them. Bad stuff happens.
@Owen Reynolds, all of the behaviors were working. Those scripts were executing correctly.
@calmcarrots, there were no scripts that said they were missing.
Basically, the way that I eventually ended up solving it was by opening up each scene that used those scripts, selecting the objects that used those scripts, and selecting "revert to prefab". Again, NOTHING changed when I did this. All settings in the editor remained the same. But this allowed me to save the scene, and after that it all ran with no problems.
So, I'm not sure if what fixed it was the "revert to prefab" thing, or if I just needed to open every scene and re-save them to get Unity to update everything under-the-hood.