- Home /
script does not update inspector?
hii, I have a big problem with updating scripts in inspector, when I write the code, I enter code and save, but by inspector the code are not saved. if I try to close unity and reopen it it seems that the code has been saved, but I should always turn it off and on. help me please!!!
Answer by Xrank · Jan 22, 2021 at 05:57 PM
Does your class inherit from monobehavior, I believe that classes need to or else it won’t update in the inspector.
public class yourClass : monobehavior {}
public class Test : $$anonymous$$onoBehaviour
{
public GameObject gO;
[SerializeField]
public GameObject gO2;
void Start()
{
}
void Update()
{
transform.position = new Vector3(2, 0, 0) * .5f * Time.deltaTime;
}
}
$$anonymous$$y class comes from monobehaviur
Hmm, first thing that I see is that you shouldn’t need to serialize a public gameobject. Can you show a picture of the inspector?
Ok, go to the project panel and find the script, select it and look at the inspector. Does it show the script you have created?
Ok so it’s not saving to unity. Is VS auto saving or are you manually saving? If it says it is saved make sure your default IDE is VS. it should be in edit, preferences. I’m not sure exactly where it is so you might have to look it up.
Answer by ChichoRD · Jan 22, 2021 at 05:44 PM
Inspector only shows fields/properties that are public or have the attribute [SerializeField]
, thus you should revise your variables. If you can give more details of your question, I'll try to help
thanks for answer, the variables were already all public and serializable
Answer by Pokedlg3 · Jan 22, 2021 at 08:07 PM
Every time you finish editing a script you have to give Ctrl + S, to save, in VS code goes in your script and press Ctrl + S that will solve.