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
0
Question by ronronmx · Aug 07, 2012 at 05:39 PM · editoreditor-scriptingongui

breaking out of OnGUI() ticks?

I'm not sure my title makes much sense but I couldn't find a better one...

My problem: I have code which runs constantly in OnGUI() for an editor window:

 GameObject fbx, model, prefab;
 bool childUpdateOnly = false;
 bool dontCheck = false;
 
 void OnGUI()
 {
     // Create selection field to allow the selection of the object to process
     model = (GameObject)EditorGUILayout.ObjectField( "Select FBX Object", fbx, typeof(     GameObject ), true );
     oldPrefab = (GameObject)EditorGUILayout.ObjectField( "Select Prefab To Update", oldPrefab, typeof( GameObject ), false );
 
     childUpdateOnly = (bool)EditorGUILayout.BeginToggleGroup( "Child Update Only", childUpdateOnly );
 
     if( model && prefab )
     {
         if( model.name == prefab.name && dontCheck == false )
         {
             childUpdateOnly == false;
         }
     }
 }

As you can see in the code above, 'childUpdateOnly' gets set on every update tick so that if the user removes a GameObject from one of the ObjectFields, it automatically gets set to the correct state. But I also want to be able to check/un-check it manually by clicking the toggle field in the EditorWindow, problem is, since the code checks for the ObjectFields state on every tick, 'childUpdateOnly' gets set back automatically so I can't manually check/un-check it.

How can I get around this problem? Is there a way to maybe use the Event system, with something like this:

 if( Event.current.type == EventType.MouseClickUp )
 {
     childUpdateOnly = !childUpdateOnly;
     dontCheck = true;
 }

But then how do I set 'dontCheck = true' if the user removes or adds a GameObject from one of the ObjectFields?

I hope I'm explaining my problem clearly enough, if not I'm sorry :) Any help will be greatly appreciated as always, thanks for your time guys.

Stephane

Comment
Add comment · Show 6
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 ScroodgeM · Aug 07, 2012 at 08:46 PM 0
Share

http://docs.unity3d.com/Documentation/ScriptReference/EditorGUILayout.Toggle.html

may be you should use this ins$$anonymous$$d of BeginToggleGroup?

avatar image ronronmx · Aug 07, 2012 at 10:21 PM 0
Share

Hey Scroodge, thanks for the quick answer. I don't want to use a regular Toggle, because I need everything within the ToggleGroup to be disabled when the user un-checks the check box.

avatar image ScroodgeM · Aug 07, 2012 at 10:30 PM 0
Share

then... don't you forget about...

EditorGUILayout.EndToggleGroup();

???

avatar image ronronmx · Aug 07, 2012 at 10:40 PM 0
Share

I do have EditorGUILayout.EndToggleGroup(); at the end of my code (which I didn't include in the example above, sorry). That part is all working fine. What I need is a way to 'override' the if() statement which happens every tick by detecting a Event, like a dragging or mouse-click Event, so that I can toggle 'childUpdateOnly' manually even if the if() statement returns true...I realize my question might be confusing, it's really clear in my head but maybe I am not explaining what I want to do correctly?

avatar image ScroodgeM · Aug 07, 2012 at 10:44 PM 0
Share

ouch... i understood now 8) i'd solve this issue once in one of my projects...

what do you think about:

childUpdateOnly = EditorGUILayout.Toggle(...);//this can be easy styled like drop-down switcher
if (childUpdateOnly)
{
    ...draw other controls
}
Show more comments

1 Reply

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

Answer by ScroodgeM · Aug 08, 2012 at 07:15 PM

unity serializes all public properties and stores it internally.

editor doesn't store any values at all. Editor class initializes every time it needed, so it can't be used to store any data at all. Editor is just a provider between you and component it created for.

'childUpdateOnly' in your case is a private variable so it will not be stored.

declare this property as public in class that this editor created for and change it in this editor on user's clicks

don't leave any needed data in editor.

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 ronronmx · Aug 09, 2012 at 12:59 AM 0
Share

Got it, I didn't know that! Thanks for the explanation, I'll give that a try.

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

How can I preserve static object/data between editor and play? 2 Answers

Resizing an array of gameObjects 2 Answers

How to record the entire game and user behaviour for a research project? 1 Answer

SetReplacementShader in Editor Utility? 0 Answers

HideFlags on children of visible objects. 3 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