I have only been working with Unity for 2 days now and decided to go with from the book ‘Learning C# by Developing Games with Unity 3D Beginner’s Guide’ (nice book for any beginner btw). My understanding is that when you write code out in Mono it automatically updates in Unity and inside the Inspector, however this is not happening for me. The code is ridiculously simple so maybe that is the issue.
using UnityEngine;
using System.Collections;
public class LearningScript : MonoBehaviour
{
public int myNumber = 29;
// Use this for initialization
void Start ()
{
Debug.Log (2 + 9);
Debug.Log (11 + myNumber);
}
// Update is called once per frame
void Update () {
}
}
I have rebuilt the project 4 times and it happens consistently. The only way to get the script to update inside the Inspector/Unity is to reset the script inside the Inspector. The script also does not update inside Mono if I make the change inside the Inspector.
I apologize if this a topic that has been gone over before. I sifted through the forums, but can’t seem to find out the WHY this is happening. Being so new I am trying to figure out the why part, so that I can better understand how to possibly avoid this in the future.
Thanks for your time everyone.
All the best.
Usually when you save a file in MonoDevelop and then switch to Unity and click on the app, the changes will appear in the inspector. Unity watches the project folder and looks for files that change.
@Graham
Thank you for your reply. I moved on to another lesson in the book and have been playing around to see if I can find out what is going on. I still have the same problem, but here is a little more detail. I can see that when I save the file in Mono and move to Unity, there is a sync process. A little circle turns in the bottom right, and more than that the script file itself inside my Projects folder does update. I can see the changes when I single click the script file I am working on in the Inspector window.
However, if I change the value for the variables of myNumber1 or myNumber2 (script below) the changes take place everywhere except the object/s that the script is a component of. In other words if I where to change the values for both variables to 10, the script file in Unity would show the changes, but the values inside the inspector for the objects do not changes.
Also, the point of this script is to be able to press the Enter button and see the results in the console window. After any changes are made, and I run the program (without resting the script inside the objects inspector) nothing happens inside the console anymore. I am sorry if that is all a little wordy for such a simple problem. I am just trying to be a detailed as possible.
Is there some setting that I possibly have to activate for the sync to happen within the object also? Thanks again.
using UnityEngine;
using System.Collections;
public class LearningScript : MonoBehaviour
{
public int number1 = 2;
public int number2 = 9;
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
if(Input.GetKeyUp(KeyCode.Return))
AddTwoNumbers();
}
void AddTwoNumbers()
{
Debug.Log (number1 + number2);
}
}
1 Like
I am having the same problem. If I enable/disable my component it starts working all of a sudden, perfectly. I know this because all I did was copy existing code, and paste it into a separate script.
Also, if I add a Debug.Log, the script again works fine on its own. Why?