[Solved] When I save the script, it forces me to redo connection

In this part of the lecture, Ben describes how to make your first script. He asks that we put in the print command with “Welcome to Number Wizard” as the string.

Please do note that I may have missed something in his lecture thus far, but I don’t believe I did.

When he tells us to run the script, my experience is that he hadn’t told us to make the connection in the Inspector to the script, therefore when I first clicked Play, my console did nothing. I found the solution to that here, and made the connection the script.

Then I did what he asked next: add another print command that says “Pick a number in your head, but don’t tell me.” When I did that and saved the script again, it deleted the connection to the script from the Inspector tab in Unity.

Is this normal behavior, or do I have something wrong? I’d assume it would keep the connection.

Edit: It appears I ran in to a bug in Unity, perhaps. If I follow the same course of action now, the connection stays and the script prints to the console just as Ben describes it. Does anyone know if this is common or am I just having a bad night?

Edit2: Continuing with the course… I’ve added the int max variable as he describes and saved the script and it removed the connection to the script again. I had to reconnect to the script in the Inspector once more and it works fine now, thus confirming this doesn’t happen every time I save my script. This is appearing to happen regularly, however. Saving the script 5 times has produced 3 times that I have to Add Component in the Inspector again.

Any ideas?

Thanks.

I didn’t seem to have any problems getting my scripts to stay connected. Let me see if I can clarify your issue, and maybe be able to come up with an idea for a solution for you.

Is what you are saying that you have a GameObject, then in the inspector clicked, New Script, then named it, then clicked create and add, and then later gone back and that script is no longer in the inspector for the same GameObject?

Yes, mostly. I created the script in the Project tab on the bottom, named it, added the code as directed. When I save that script, there is a good chance the script component will leave the Inspector tab for the GameObject (being NumberWizard under the Hierarchy tab).

This is happening roughly about 75% of the time.

Ah I see. It will be tough for me to help exactly, as I have never done it that way.

Whenever creating a script, in the hierarchy, I will select the GameObject I want to add the script to. Then it will pop up in the inspector. Now in the inspector you can click “Add Component” and handle the script adding from there. If it is the first time you are creating a script, you will select new script, and go about it that way, and if you are reusing a script from before, just select the script button, and it will give you a list of scripts you have already written to select from.

This is how I always do it, and I have never had the issue you are talking about, and it is really quick and simple, saving you time from creating the script in one place, and then dragging it to anothe.r

I hope this will be some sort of help to you!

Disclaimer: I am only up to the Laser Defender Section, so I am by no means an expert. Just a fellow student trying to help another

To clarify:

You can see the component in the Inspector here (red arrow). That component is the script, clearly. That script is open in Mono and I am writing code in to it as I go. It is located in the Scripts folder (blue circle).

When I save the script in Mono, about 75% of the time it removes the component from the Inspector and I have to add it again.

Ah. Now that you mention it, that is how he created THIS script. But in the earlier lessons, Ben (I believe it was Ben anyway) explains that you can do it either way. If it removes itself again, I’ll use the add component button and report back. Perhaps it’s a bug in the old version of Unity.

Thanks for the input! :slight_smile:

This problem seems to have gone away. I can confirm it was happening, and I am mostly positive it was because I created my script from within the Assets tab rather than using the Add Component button in the Inspector.

I suggest only creating new scripts with the Add Component button. I assume this is a bug with Unity 4 and has likely been fixed somewhere in the multiple updates between the version he suggests you use now and the current version.

Privacy & Terms