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 dCalle · May 24, 2018 at 05:26 PM · editorupdatescriptableobject

Is there a method that gets constantly updated in the editor?

Hey folks.

I finally found out how to use the 3rd and 4th MouseButtons, but now I need to constantly check for them.

Problem is I don't know of any method besides [ExecuteInEditMode], but actually I really don't want to use a GameObject and MonoBehaviour just for that ( just turned all of my Singletons to ScriptableObjects).

isn't there some magical Method or Class out there, that could help me out?

Thanks

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
2
Best Answer

Answer by Tobychappell · May 26, 2018 at 08:27 PM

UnityEditor.EditorApplication.update

https://docs.unity3d.com/ScriptReference/EditorApplication-update.html

     [UnityEditor.InitializeOnLoad] // <<< IMPORTANT
     public class TestClass
     {
       static TestClass()
       {
         UnityEditor.EditorApplication.update += MyMethod;
       }

       private static void MyMethod()
       {
         Debug.Log("MyMethod!");
       }
     }


alt text


tempimage.png (59.7 kB)
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 Tobychappell · May 26, 2018 at 08:28 PM 1
Share

You may want to wrap the whole script in a preprocessor

[hashsymbol]IF UNITY_EDITOR

...

[hashsymbol]ENDIF to avoid build errors

avatar image Bunny83 Tobychappell · May 27, 2018 at 12:07 AM 0
Share

Uhm he specifically ask for an in-editor usage. So we talk about an editor class anyways. So the preprocessor tags are not required as long as the script is inside an editor folder.

avatar image Tobychappell Bunny83 · May 27, 2018 at 12:41 AM 1
Share

I'm just going off what was in the question without assu$$anonymous$$g things:

  1. @dCalle asked: "Is there a method that gets constantly updated in the editor?"

  2. This is 'in-editor' usage as in "the" UnityEditor application.

  3. dCalle said he didn't want to be using a GameObject or $$anonymous$$onoBehaviour.

  4. An Editor's OnSceneGUI method is only called if it is set to be a custom editor of another $$anonymous$$onoBehaviour that is on a GameOebject that is in the current scene and has to be selected and there is mouse activity inside the SceneView.

An Editor class is usually the way to go, but without information on purpose i can only advise based on the requirements.

avatar image dCalle · May 27, 2018 at 08:52 PM 0
Share

Nice, this looks good. Actually I went for EditorWindow, but this method looks way better. I check it out tomorrow. Thanks Buddy ;-) But one Question: When do you prefer InitializeOnLoad over DidReloadScripts? Ah and yeah, I forgot to tell you but It should've been an editor Script. But if I ever intent to use a combo, I know where to look ;-)

avatar image Tobychappell dCalle · May 28, 2018 at 12:41 AM 1
Share

Im not sure what you mean by DidReloadScripts, unless you meant Editor Scripts?, This can be used(is normally used) with editor scripts. InitializeOnLoad will initialize classes when Unity loads, so this will call the static constructor of a class, Unity docs say it loads editor classes but this proves that it doesn't have to be an editor class. This can be when the UnityApplication opens and when Run is pressed, and maybe when the code is recompiled..

I found this interesting as it opens up possibilities to be able to get an update regardless of what I was doing in editor and don't need to rely on having a monobehavior to have an editor for, like as if it was a background progress in Unitys Application.

Why you might want this over an editor class would depend on if the functionality was involved with a particular system or component or if you wanted to be completely abstracted away from Unity components. ExecuteInEdit$$anonymous$$ode is another way but then you need a game object with that script in every scene, perfor$$anonymous$$g editor stuff in the game environment, which will end up in your game if you're not careful.

avatar image dCalle Tobychappell · May 31, 2018 at 09:53 AM 0
Share

Alright thanks for the info. I thought of EditorScripts. And just thought I wasted the last couple of days circumventing the need for DidReloadScripts. But since InitilaizeOnLoad only calls the static constructor (which is easy-peasy) I'm kinda happy having found a (tiresome) solution to get all non-static, non-$$anonymous$$onoBehaviour/ScriptableObject (field)objects and call their method (provided by an interface) on recompile.

haha still didn't check out your solution above, but I'm probably gonna do that... today^^

Still a huge thanks for your support and nice talking to you ;-)

avatar image
0

Answer by Lost_Syndicate · May 24, 2018 at 05:52 PM

use this:

  [ExecuteInEditMode]
     public class PrintAwake : MonoBehaviour
     {
         void Awake()
         {
             Debug.Log("Editor causes this Awake");
         }
     
         void Update()
         {
             Debug.Log("Editor causes this Update");
         }
     }

Found Here

Note you can remove MonoBehaviour

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 dCalle · May 26, 2018 at 05:07 PM 0
Share

Nope, doesn't work without being 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

118 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 avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

How to use "SerializeObject" with an object which doesn't derive from Object? 1 Answer

Display Custom Inspectors for each class in a List<> 1 Answer

Release Note tracking for specific platforms such as WebGL 0 Answers

Unity 2020.2 crashes when loading my Unity 2020.1 project 0 Answers

Unity Custom Inspector - Resources.LoadAll() returns 0 element. 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