- Home /
OnGUI() not being called in Monobehaviour
I've got two cameras, and the OnGUI() isn't being called in both of them. I tried using the working OnGUI to send a message to the second camera to call it's OnGUI but I get the error that there is no receiver.
CameraControls.cs (main camera)
//caled once per frame
void OnGUI(){
Debug.Log ("CameraControls.OnGUI() called.");
//call the OnGUI() for the PlayerInventory that sets up the quickbar contents
Transform cameraChild = transform.Find ("InventoryCamera");
cameraChild.gameObject.SendMessage ("OnGUI");
}
PlayerInventory.cs (child of main camera)
//used for GUI
void OnGUI(){
Debug.Log ("PlayerInventory.OnGUI() called.");
//other code, but the above is not printing
}
I know this looks unorthodox, but Unity isn't calling PlayerInventory.OnGUI() automatically. It does have a GUILayer component. I've also tried renaming the OnGUI function for this setup with the same results, even though I successfully call other functions from PlayerInventory.cs with this script.
Quick-tip : Don't use transform.Find("") in OnGUI() like that. Use it one time in Start() for something like you're doing.
Are you absolutely sure that PlayerInventory
is attached to anything in the scene? Is it enabled?
@Lo0Nuhti$$anonymous$$ I'll keep that in $$anonymous$$d. This was a quick thing for debugging only.
@rutter Yes, I'm sure it's attached and enabled. I've also deleted the camera, and set up a new one to see if there was some other detail I tweaked, but the problem persists.
Answer by No_Username_Found · Jun 04, 2014 at 05:04 PM
Problem solved.
I had a variable in the PlayerInventory.Start() left over from previous debugging. active = false;
Seems that it works like enabled = false;
Sorry about the false alarm.