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
3
Question by delstrega · Jul 10, 2012 at 03:23 PM · updatecustom editorsceneview

Custom Inspector - Update() alternative?

Hi! I'm trying to move the "preview" functionality from a separate window (which is created by clicking a button in my custom inspector) to the SceneView itself. The problem is, that the class "Editor" has no Update() function to override. From what I've seen there is no function at all that gets called as frequent as I need it. This is bad since while doing the "preview" I have to calculate and update variables very often.

I thought about simply creating an invisible EditorWindow and using it's Update() to do everything but maybe there is a more elegant solution.

On a sidenote - is there a way to manipulate the SceneCamera's cullingMask so I only get to see the objects I like while doing the "preview"? (by code I mean)

Thanks in advance,

delstrega

Comment
Add comment · Show 4
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 Mr.Jwolf · Jul 10, 2012 at 03:38 PM 0
Share

The editor class doesn't have a "Update()", it has a "OnInspectorGUI()"

http://docs.unity3d.com/Documentation/ScriptReference/Editor.html

avatar image delstrega · Jul 10, 2012 at 03:42 PM 1
Share

Yeah I know. That's exactly my problem. OnInspectorGUI() doesn't get called frequently but only if the inspector needs a redraw. There must be something I can do... :(

avatar image Statement · Jul 10, 2012 at 04:40 PM 1
Share

Call Repaint at the end of the call?

avatar image delstrega · Jul 10, 2012 at 06:15 PM 1
Share

I tried calling this.Repaint() and must say - yeah it works. OnInspectorGUI() gets called like crazy. The downside is, that everything I have in there naturally gets executed very often now - even if it's time consu$$anonymous$$g or just not necessary per se - like GUI stuff :D Well, I bit the bullet and just created an invisible EditorWindow and do the stuff in it's Update. This way I get the benefit of only doing the stuff I want in Update and keep the redraws to a limit. Thanks though for the great idea - it's just not practical with how I setup my custom inspector. :) Repost your comment as an answer please so I can close this thing:)

1 Reply

· Add your reply
  • Sort: 
avatar image
4

Answer by scanzy · Jul 24, 2016 at 10:00 PM

You can use EditorApplication.update and bind it to your Update function

 public class YourInspector : Editor
 {
     void OnEnable() { EditorApplication.update += Update; }
     void OnDisable() { EditorApplication.update -= Update; }
 
     void Update()
     {
        //your code here...
     }
 }

Note this will call Update function only if you see the inspector: If you want the function to be called also when you are not seeing the Inspector (e.g. you have selected another object) use this instead:

 public class YourInspector : Editor
 {
    [InitializeOnLoadMethod] 
    public static void InitUpdate() { EditorApplication.update += Update; }
 
    static void Update() 
    {
        //your code here...
    }
 }
Comment
Add comment · Show 6 · 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 imc_AG · Jan 24, 2018 at 01:56 PM 0
Share
 EditorApplication.update -= Update;

Does this line even work? from what I read, it should not.

avatar image Bunny83 imc_AG · Jan 24, 2018 at 02:13 PM 1
Share

Uhm, yes it should. Where did you read it doesn't? You know how multicast delegates work?

When doing this:

 EditorApplication.update += Update

You actually do

 EditorApplication.update = Delegate.Combine(EditorApplication.update, Update);

$$anonymous$$ulticast delegates are actually implemented as linked list but the implementation detail is irrelevant. The point is that you can combine several delegates into a single one that way.


When you do this

 EditorApplication.update -= Update

You actually do

 EditorApplication.update = Delegate.Remove(EditorApplication.update, Update);

The Remove implementation will search through the list of delegates and will remove the delegate with the same target object and method reference.

avatar image ivan-santiago Bunny83 · Apr 18, 2019 at 08:38 AM 0
Share

It doesn't work because is being called within a Static method. For that to work, Update should be static aswell.

Show more comments

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

10 People are following this question.

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

Related Questions

Scene view controls locking up > trying to make scene view generic menu on right click 0 Answers

Show transparent version of prefab before instantiation 1 Answer

How to set SceneView culling mask programmatically? 1 Answer

Always show Custom Editor GUI 1 Answer

why is every 2. frame is weird with Time.deltaTime 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