ScriptableObject ExecuteInEditMode issue
Hello everyone. I'm busy building a CustomInspector for the artists in my office so they can create items without having to know code. This whole thing has been way easier in theory than it has been in practice.
My current problem is that I want to use ScriptableObject instead of MonoBehaviour but the code I've written requires some stuff to use [ExecuteInEditMode], when I change the script from MonoBehaviour to ScriptableObject [ExecuteInEditMode] stops working.
Does anyone know if it's possible to use [ExecuteInEditMode] in a ScriptableObject? If it is I'd greatly appreciate a pointer or two.
Check out: EditorApplication.update https://docs.unity3d.com/ScriptReference/EditorApplication-update.html
This delegate event allows your code to be called back, every cycle in the editor. Still, I would recommend you follow Bunny83 advice on what kind of code to put in there. (e.g. you may wish to create a separate editor component class for your scriptable object, and use THAT to perform whatever editor-functionality you need, including subscribing to EditorApplication.Update.)
Answer by Bunny83 · Oct 05, 2018 at 11:29 AM
Uhm a scriptableobject has almost no callbacks at all. It only has Awake, OnEnable, OnDisable and OnDestroy. What exact behaviour do you expect from ExecuteInEditMode ? Have you read the documentation? It only applies to MonoBehaviours since ScriptableObjects do not have any callbacks besides the 4 i've mentioned already. Those callbacks are actually called in the editor as well.
Finally note that ExecuteInEditMode is not meant to implement editor functionality. It's only meant to provide the runtime functionality to be active at edit time. For example a particle system that should update during edit mode. However it should not be used to implement actual editor features. You haven't said a word about what you're actually doing so we can't help you further with your issue. However the way you phrased your question it sounds like you're generally on the wrong track.
Thanks for the reply and sorry for the delay. It was a packed weekend. That was what I was afraid of actually, I'll take your word that ExecuteInEdit$$anonymous$$ode was not intended to add editor functionality. Unity has been fighting me every step of the way on this. I'll abandon this method and try some in engine UI ins$$anonymous$$d.
Your answer
Follow this Question
Related Questions
Adventure interactionSystem Structure (ScriptableObject,MonoBehavior,POO?) 0 Answers
Call method of a behaviour from a scripotableobject 0 Answers
How do I decide which Conversation to start when clicking on an NPC? 0 Answers
ScriptableObject not Serializing? 0 Answers
Can't you add tags using a script instead of tagging it through the editor ? 1 Answer