1

I'm using Unity 2018.4.0f1 for an introductory course on Unity.

For some reason, Unity is not updating my script, even after saving on Visual Studio and being displayed correctly in my Unity scripts folder.

This is a snippet of my program from Unity, which is being displayed correctly.

enter image description here

However, whenever I enter Play Mode the attributes reset to the values I had in the pre-updated script.

enter image description here

My program is quite simple, hence I'm certain this is not a software issue. I also found similar issue raised here:

https://forum.unity.com/threads/why-is-unity-not-updating-my-scripts.497383/

As well as here:

https://answers.unity.com/questions/17460/unity-is-not-updating-my-scripts.html

None of these contain a conclusive answer, and I haven't been able to resolve this issue.

My full program is below:

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class PlayerController : MonoBehaviour
{
    public float speed = 10.0f;
    public float turn = 25.0f;
    public float horizontalInput;
    public float verticalInput;

    // Start is called before the first frame update
    void Start()
    {
        
    }

    // Update is called once per frame
    void Update()
    {
        horizontalInput = Input.GetAxis("Horizontal");
        verticalInput = Input.GetAxis("Vertical");

        // We'll move the player forward
        transform.Translate(Vector3.forward * Time.deltaTime * speed * verticalInput);
        transform.Rotate(Vector3.up, Time.deltaTime * turn * horizontalInput);
    }
}
5
  • 2
    That's because you previously modified the values in the inspector. If you set asset serialization to text mode, you'll be able too see the modifications inside PlayerController.cs.meta. You can right click your property and press reset to discard the changes, and then updating your values inside your script, will also update them in the inspector. Commented Oct 26, 2020 at 20:39
  • @EmanuelVintilă Yes I had indeed previously modified values in the inspector. How can I make Unity use my script again? Commented Oct 26, 2020 at 20:47
  • @EmanuelVintilă Actually could you clarify what you mean by property? Do you mean the fields speed and turn? Commented Oct 26, 2020 at 20:50
  • 2
    Yes the fields as shown in the inspector. You can right click on their names, or just reset the script altogether. Commented Oct 26, 2020 at 21:05
  • @EmanuelVintilă Ah yes, I've managed to fix it. Thanks very much. Commented Oct 26, 2020 at 21:09

1 Answer 1

2

When you have public variables that are also serialized, the value from editor overrides the value declared in the script, you'd probably have to delete some meta data of the scene to completely reset it. Just change it from editor, or make those values private, then editor won't have access to them and won't change the values

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.