Can't draw GUI in Update() anymore?

So here is my Manager to make things all clean, :3 The point in this is to make everything GUI Related in one script… Just having a problem with the GUI…

You used to be able to draw GUI functions in Update()
although now you can’t, you must put them in OnGUI(), but the problem is… you can’t call OnGUI() from another script, you can only call Update()… Which makes this very confusing for me.

This is the way I used to do it

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

public class ApplicationManager : MonoBehaviour {
	
	//Declaring HealthManager as an instance
	public static ApplicationManager instance;
	

	// getting the instance, if it doesn't exist create a new one.
	public static ApplicationManager GetInstance()
    {
        if (instance == null)
        {
            instance = new ApplicationManager();
        }
        return instance;
    }
	
	public ApplicationManager() {

	}
	
	// Use this for initialization
	void Start () {
		instance = this; // Sets the instance to itself
	}
	
	// Update is called once per frame
	void Update () {
		HealthManager.GetInstance().Update();
		ExperienceManager.GetInstance().Update();
		StatManager.GetInstance().Update();
            GUIManager.GetInstance().Update();
	}
}

Although I get the error “GUI Functions can only be called from within OnGUI”

So I attempted to change GUIManager.GetInstace().OnGUI();

Which gave me the same error… O_O

If you want to keep everything as part of ApplicationManager, and ApplicationManager is the only class that is inheriting from MonoBehavior, then try calling the GUI functions from ApplicationManager’s OnGUI() function.

Thus, ApplicationManager would look like:

void Update () {
   HealthManager.GetInstance().Update();
   ExperienceManager.GetInstance().Update();
   StatManager.GetInstance().Update();
        
}
void OnGUI() {
    GUIManager.GetInstance().Update(); // Or GUIManager.GetInstance().OnGUI();
}

You really should never call Unity callback fucntions manually. Just use your own functions for this. Common names for Update-like functions are “Think”, “Do”, “Execute”, “Process”.

Your main problem however is that you can’t use any GUI stuff in “Update”. With Update i talk about the Unity callback, not your own functions. The restriction for GUI stuff comes from the fact that Unity has to prepare the engine for GUI drawing. When Unity is ready to draw the GUI it calles the OnGUI callback. Again it’s important that Unity invokes OnGUI. When you call OnGUI from Update it won’t work.