Update Function Not Being Called

Using breakpoints and other methods, I believe I have proven that the Update function is never being called (but Start definitely is). I am probably missing something obvious; but can anyone see what I am missing?


using UnityEngine;
using System.Collections;

public enum UserDisplayStates {Idle,
			DisplayingMessage,
			};

public class UserDisplayScript : MonoBehaviour {
	public UserDisplayStates State { get; set;}
	private LayoutPropertiesScript _LayoutPropertiesScript;
	public string Message;
	
	// Use this for initialization
	void Start () {
		State = UserDisplayStates.Idle;
		if (!_LayoutPropertiesScript) {
			_LayoutPropertiesScript = GameObject.Find("LayoutProperties").GetComponent<LayoutPropertiesScript>();
		}
	}
	
	// Update is called once per frame
		void Update () {
		if (State == UserDisplayStates.DisplayingMessage) {
			if (Input.GetKeyUp(KeyCode.JoystickButton0)) {
				State = UserDisplayStates.Idle;
				Message = null;
			}
		}
	}

		public void DisplayMessage(string message) {
		State = UserDisplayStates.DisplayingMessage;
	}
	
	
	void OnGUI() {
		if (State == UserDisplayStates.DisplayingMessage) {
					GUI.Box(new Rect(
					_LayoutPropertiesScript.HorizontalCenter-400/2 - 10,
					_LayoutPropertiesScript.TopEdge + 45,
					400, 510),
					Message);
		}
	}
	

	
}

The reason why Update() doesn’t seemed to be called is that the if statement in it only triggers if “State” equals “UserDusplayStates.DisplayMessage” which, based on the code you’ve provided is never set. The OnGUI() funciton also looks for UserDisplayStates to be set as “DisplayMessage” but in Start you set UserDIsplayStates to “Idle”.

Those conditional checks never account for “Idle” state which is what you’ve set. Add a condition for when “YserDIsplayStates” is set to idle.

I found the issue here, but I’m not sure who to give credit for the answer here. Everyone’s comments helped.

The problem is I had in another class code similar to this:


while (UserDisplayScript.State != UserDisplayStates.Idle) {
   //Do nothing until the user presses A
}

I was thinking that the other class would then wait until this class went idle, then continue on. I think what happened is the other class went into an endless while loop and never completed it’s Update(), and therefore this Update() indeed did not run.

I changed the while to an if statement, and that resolved the issue.