[Request] Better editor scripting support

Forums 💬 NodeCanvas 🗨️ General Discussion [Request] Better editor scripting support

Viewing 9 posts - 1 through 9 (of 9 total)
  • Author
    Posts
  • #12968
    gotenxds
    Participant

      Hi, I would like to request a couple of small features that while not impossible to workaround today, adding them would most likely be a small change and would help me write my editor utilis more cleanly.

      1. Make OnValidate fire when the editor values changes – Align it with unity behavior for OnValidate
      In the unity scriptable objects and editors the OnValidate is fired when the state of the editor changes, this allows for writing validators or side effects to the editor data, in the Task api OnValidate is only fired on when the task is created/duplicated/initialized

      2. Expose OnSceneGui from the GraphOwner (editor) so we can use Handles to create more usable gui editors.
      For example, when having a list of vectors on a task we can draw them using OnDrawGizmosSelected but we cannot move them, to do that usage of the HandleAPI is required.

      #12976
      Gavalakis
      Keymaster

        Hello again and sorry for the late reply. Thank you for your suggestions.

        1) Right now the “OnValidate” in Tasks is also called from the “OnEnable” callback in the Graph class (which is a ScriptableObject of course). In Graph.cs at line #59, there is also an “OnValidate” callback, but it is unused right now since it just fires at the same time the “OnEnable” is fired (or at least so I’ve seen). You can modify the code there to call “Validate()” in the “OnValidate” unity callback. Is this also where you meant you want Validate to be called?

        2) That would be interesting. I have added this on the roadmap 🙂

        Thank you.

        #12975
        gotenxds
        Participant

          Hya Glvalakis, thanks for the replay,
          I tried calling validate where you suggested

          And then I added a log to my action OnValidate method like so:

          This does not seem to work, did I misunderstood?

          #12974
          Gavalakis
          Keymaster

            Hello again. Yes this is what I meant. The OnValidate is the only callback that Unity provides for Validation on scriptable objects (isn’t that what you originally meant as well?), but as I mentioned above, this callback is not fired when the editor values change as you’d expect. Unfortunately though this is the only callback that Unity gives us nonetheless.

            I probably misunderstood your suggestion though. Do you mean that you would like task OnValidate to be called when that task’s inspector values change in the NodeCanvas editor? 🙂

            Let me know.

            #12973
            gotenxds
            Participant

              Yes, I would like some way to run code when the inspector values change (validate them)

              This is odd as from my experience the native onValidate does trigger on editor value changes.
              Actually a quick check in the unity docs verifies that https://docs.unity3d.com/ScriptReference/MonoBehaviour.OnValidate.html
              First line states it should fire when inspector values change.
              I can only assume that the task inspector is somehow “disconnected” from the main graph

              #12972
              Gavalakis
              Keymaster

                Yes the task inspector use a custom made inspector UI and the graphs are also serialized with a custom serialization system instead of Unity native, and this is why OnValidate is not fired like it would. However adding your suggestion is easy. To do this now, please open up TaskEditor.cs and add this line of code just after line #169.

                Here is the code nearby to get a full view where to add it (its the last line here)

                Let me know if that works for you.

                #12971
                gotenxds
                Participant

                  Works great, thanks Gavalakis, any chance this comes bundled in the next version (I dont want to remember adding it everytime I upgrade)

                  BTW, I was able to make OnSceneGUI Work by adding these changes, dont know if this is the best way to do that with the graph structure, let me know if you think it’s fine and if you can add it

                  GraphOwner class

                  Task class

                  #12970
                  Gavalakis
                  Keymaster

                    Hello again,
                    Yes, that would be included in the next version.
                    Your OnSceneGUI implementation is fine, however it can be implemented in a way so that the OnSceneGUISelected is also called in Edit-time (I presume it is better than only be called in play-mode). I will look into this.

                    #12969
                    gotenxds
                    Participant

                      Yes, That would be better but I could not find a good place to insert the event registration, Thanks!

                    Viewing 9 posts - 1 through 9 (of 9 total)
                    • You must be logged in to reply to this topic.