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
2
Question by Herman-Tulleken · May 26, 2011 at 08:42 AM · editor-scriptingupdate

When is Update called in edit mode?

I can't tell exactly when it is called, it is certainly not each frame. It is called sometimes when I change something, but it looks like it is not always called.

When exactly is it called, and is there any way for me to signal an update is necessary from an editor script?

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

3 Replies

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

Answer by Bunny83 · May 26, 2011 at 09:31 AM

The editor redraw isn't run in a gameloop like the games you create with Unity. It's completely event based like every window in Windows ;).

OnInspectorGUI or OnGUI in EditorWindows are only called when it needs an update. This is for example when you move the mouse and stop moving for 1 sec the tooltips are displayed. Therefore a repaint is done.

For EditorWindows you can use `EditorWindow.Repaint`. The inspector should be fine.

If you need something that is executed regularly you can use a delegate to hook into the editor update (which runs about 100 times per sec.). This update have nothing to do with visual frames.

If you enable `EditorWindow.wantsMouseMove` for your windows the OnGUI function is called each time you move the mouse, but ONLY to pass a mouseMove event. Still no repaint is done. You can use this code to do a repaint when the mouse is moved.

 // C#
 void OnGUI()
 {
     if (Event.current.type == EventType.MouseMove)
     {
         Repaint();
     }
 }

If you care about updating the sceneview(s) you can use SetDirty like Tom 17 said or just call Repaint. You can Repaint any EditorWindow as long as you can access it. SetDirty only marks an object to be "dirty" and it needs to be repainted but i guess if ths object isn't visible no repaint is executed (haven't tried).

The SceneView is derived from EditorWindow.
SceneView.lastActiveSceneView gives you the last active sceneview (but check it for non null!!) SceneView.sceneViews is an array that includes all open sceneviews. The sceneview class isn't documented but if you use Visual Studio you have intelliSense ;).

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 Herman-Tulleken · May 26, 2011 at 10:14 AM 0
Share

Thank you for this more detailed answer. I think now I know what is going on, and why my code was behaving strangely. I'll verify and then accept the answer ;)

avatar image Joshua · May 26, 2011 at 10:37 AM 0
Share

Perfect answer - and no need to verify, he's right :p

avatar image
2

Answer by Tom 17 · May 26, 2011 at 08:52 AM

This works in OnInspectorGUI for custom inspectors

 
if (GUI.changed)
{
    EditorUtility.SetDirty (target);
}
 

If you meant the Update() function that is available with EditorWindow, that seems to be called frame-indepentently.

If you care to be a bit more specific in your question I will edit my answer to be more precise, too. Though I hope that helped you allready.

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 Herman-Tulleken · May 26, 2011 at 09:15 AM 0
Share

Thank you, I think this is what I have been looking for (SetDirty). Unfortunately, I am getting inconsistent behaviour because of another issue, so I can't say for sure. (Once sorted I'll report back).

avatar image
0

Answer by tkamruzzaman · May 04, 2016 at 06:55 AM

The functions are not called constantly like they are in play mode. Update is only called when something in the scene changed.

Link: http://docs.unity3d.com/ScriptReference/ExecuteInEditMode.html

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

Is there a scene setup call or update for editor scripts? 3 Answers

RectTransform.rect.width/height Incorrect On Editor Startup 1 Answer

How to assign multiple EditorApplication.update delegates in JS? 2 Answers

coroutines : trouble editing and accessing the same public variable 4 Answers

Updating assets changes .meta files and breaks dependencies. 1 Answer


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