Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.

Bug "Script" components have editable field

Discussion in 'Editor & General Support' started by Kaivian, Jun 9, 2021.

  1. Kaivian


    Jan 18, 2018

    In the above example, you can see that the script field in AI Destination Setter can be edited, and HealthDisplay cannot be edited (default). I consider it a bug that it can be edited, as a mis-click on the "target" button will erase all the set fields in the component, which frustrated me a lot as a beginner (didn't know what was happening), and as an advanced user, I find annoying.

    I have found there's two cases where this happens. The first are for custom classes that inherit and extend monobehaviour. The second is when the script employs any kind of custom editor code at all.

    This results in a lot of scripts with this bug, especially those in asset packages or made by advanced users (for people who aren't necessarily adept at unity).

    To fix this bug, I think the editor should be changed so that in these circumstances, the script field is still read only. Another option, which would actually clean up the editor, is to totally eliminate the script field. As is, you can currently right click the header and select "edit script." This component does that:


    Btw, these components are from the very popular A* pathfinding project store asset.

    I have seen this problem in many popular assets.
  2. Kurt-Dekker


    Mar 16, 2013
    After you mis-click, can you restore the fields by re-dragging the proper original script onto the above slot?

    It used to be that you could always drag fresh scripts into this slot, which was actually super-useful.

    Or what about a good old CTRL-Z to back up and undo?

    Otherwise, please consider using source control in order to guard and protect your hard-earned work.

    Personally I use git because it is free and there are tons of tutorials out there to help you set it up.

    As far as configuring Unity to play nice with git, keep this in mind:

    Here's how I use git in one of my games, Jetpack Kurt:

    Using fine-grained source control as you work to refine your engineering:

    Share/Sharing source code between projects:

    Setting up the right .gitignore file:

    Generally setting Unity up (includes above .gitignore concepts):
  3. Kaivian


    Jan 18, 2018
    So I'm talking about if you changed fields from their default. Like, lets say you have a script that has an array of game objects. Maybe it's every npc in the scene. You're using this to avoid "find" calls that cause slowdowns. If you mess up this script, now you need to drag 20 npcs back into the array. This is just an example I came up with, so don't get too caught up on the details.

    I think the skipping the steps of "remove component" and dragging a script into the inspector, for the rare case you want to replace one script, doesn't warrant the problems this can cause. It also doesn't fit the workflow of every other component. Want to replace a sphere collider with a capsule collider? You remove the sphere, then add a capsule collider with the inspector.

    It doesn't seem to repopulate values in scripts totally.

    Yup, I use git, but you're still talking about spending 5-10 minutes quitting everything, pulling the scene file, and then restarting Unity. It's not a super long time, but it's a real annoyance. Also, I'm taking into consideration new Unity users who are more likely to not understand how things got messed up, how to fix them, and are 10 times more likely to be using assets that have this "bug."
    Kurt-Dekker likes this.