Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
1
Question by kvdleij · Jul 13, 2012 at 11:01 AM · guionguiargumentexception

GUI functions inside OnGUI giving argument exception

I'm using the following code:

 using UnityEngine;
 using System.Collections;
 
 public class TestScript{
  
  private GUISkin custom_skin;
  public bool guiEnabled;
  
  public TestScript(GUISkin new_skin){
  custom_skin = new_skin;
  }
  
  public void OnGUI(){
  if(guiEnabled){
  GUI.skin = custom_skin;
  GUI.Label(new Rect(0,0,50,50),"Blah");
  }
  }
 }

The problem is that I'm also getting the following error: ArgumentException: You can only call GUI functions from inside OnGUI.

It works fine in another script that is running in the same scene, but for some reason this one won't. I looked at the other script, and it's all set up in exactly the same way, but for some reason I'm getting this error all of a sudden.

Comment
Add comment · Show 1
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Minay · Jul 03, 2014 at 05:24 PM 0
Share

I am inheriting $$anonymous$$onobehaviour, still it is not working. Please help

2 Replies

· Add your reply
  • Sort: 
avatar image
2
Best Answer

Answer by whydoidoit · Jul 13, 2012 at 11:03 AM

Your TestScript doesn't inherit from MonoBehaviour so I presume you are calling its OnGUI yourself somewhere - it needs to be called from within a real OnGUI for it to work.

Comment
Add comment · Show 2 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Bunny83 · Jul 13, 2012 at 11:41 AM 0
Share

Exactly ;)

avatar image kvdleij · Jul 13, 2012 at 01:05 PM 0
Share

Yeah, apparently that was the problem. I was calling the OnGUI from within the Update from another script, and a colleague pointed out to me that that was the problem.

avatar image
0

Answer by jetty112 · Oct 19, 2012 at 06:14 PM

I am trying to use a similar thing, but the OnGUI() in the class wont work for the class objects. I want to call a render function in another script that then renders the class object, but the script never runs the OnGUI() function of that class object. What do?

Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image whydoidoit · Oct 19, 2012 at 07:41 PM 0
Share

Please don't ask additional questions as an answer to a previous question. Use a comment or ask a new question and post a link to the related item.

OnGUI is only called in a $$anonymous$$onoBehaviour. If you want to write GUi code in another class you must call that code from a $$anonymous$$onoBehaviour.

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

8 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

OnGUI Button 1 Answer

Making a text box appear after a certain gameObject is destroyed 0 Answers

Filling image without compromises 0 Answers

GUILayout.Label is not displaying on level load 1 Answer

Script is not working help plz 0 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges