Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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
0
Question by ErikSod · Sep 03, 2011 at 10:26 PM · errordrawguistyle

Error on GUIStyle.Draw

Hello,

I'm seeing this error when rendering a custom list box class.

Style.Draw may not be called if it is not a repaint event UnityEngine.GUIStyle:Draw(Rect, GUIContent, Boolean, Boolean, Boolean, Boolean) GameObjectListItem:DrawItem(Rect, GUIStyle, Boolean) (at Assets/GameAssets/UX/Core/GameObjectListBox.cs:199) GameObjectListBox:OnGUI() (at Assets/GameAssets/UX/Core/GameObjectListBox.cs:88)

It is drawing the individual elements, but it's also throwing this error what looks to be every other OnGUI.

The list box class inherits from MonoBehavior and implements OnGUI and inside that it iterates through the individual items and calls the above DrawItem method. The individual list box items are not MonoBehavior items and don't implement OnGUI.

Any ideas? Do I need to redesign so the individual items inherit from monobehavior?

Comment
Add comment
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

2 Replies

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

Answer by Bunny83 · Sep 04, 2011 at 01:49 AM

It doesn't matter where your code is located. It can be in any kind of function event of a different script. The important thing is that it's always called from within a OnGUI function. You can't use GUI stuff outside a OnGUI function but as long as you call your functions from OnGUI in ok.

Your problem have nothing to do with the location of your code. That's a bit tricky and not that obvious when you work with it the first time. OnGUI is called several times per frame! The Event class is the big brother of OnGUI. Event.current holds the current instance and Event.current.type specifies the reason why OnGUI has been called.

There are two EventTypes that fires always each frame:

  • EventType.Layout

  • EventType.Repaint

The first one can be disabled with MonoBehaviour.useGUILayout for a single script which doesn't want to use GUILayout stuff

There are other events for all sorts of input messages (mouse, keyboard). The utility functions that comes with Unity like GUI.Button() checks internally what's the current event and do different things. OnKeyUp the button have to react to the input and might return true when the cursor is within it's rectangle. All drawing however can only be done in the repaint event.

When you use GUIStyle.Draw manually in OnGUI you have to make sure that it's only called in the repaint step:

 if (Event.current.type == EventType.Repaint)
 {
     myStyle.Draw(...);
 }


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 ErikSod · Sep 04, 2011 at 03:31 PM 0
Share

Excellent, thanks very much. I should have read the documentation more closely.

avatar image
0

Answer by azizkale · Feb 13 at 10:52 AM

There can be a Button in your hierarchy that has a missing script in its onClick and your Button can want to access to it

Comment
Add comment · 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

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

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

Unsupported int type GUIStyle 1 Answer

Console error when trying to use gizmos? 2 Answers

GUI.Label Error 1 Answer

ArgumentException: Getting control 1's position... 0 Answers

Why do i keep getting this error? 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