Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Simple Graph editor to display script variables

Discussion in 'Editor & General Support' started by Thiem, Jun 26, 2019.

  1. Thiem

    Thiem

    Joined:
    Jun 30, 2014
    Posts:
    20
    Hi,
    I'm trying to create an AI behaviour tree. For now I construct the tree in the editor, like shown in the attached image.


    UnityAI.png
    The idea is just, that every turn I attempt to find an action to perform. I do this by traversing the tree. Each condition node must be checked to be true, in order for the sub-tree to be searched for actions. The above is just a simple example, the subtrees can be much larger.

    So I have two base classes: Action and Condition, from which I can inherit and create new scripts.

    This quickly becomes hard to find my way around when using the scene editor, so I'm looking for a graph editor to visualize stuff that can handle nodes and attached Monobehaviours.

    I've found a couple of graph editor tutorials and the like, e.g.:

    UnityAI2.png


    But all of these come with "hardcoded" graph nodes. If I want a new type of node, I have to create a new node type, and edit my graph editor to be able to create this type of node, and create a custom view for this new type of node.
    Or I can use a node with a reference to a scriptable object, and the scriptable object can have variables with data, which I can change in the Inspector, but scriptable objects save their data, so I'm going to need many instances. E.g. if two enemies have different range, I need a ScriptableObject of type "InRange", and create instances like "InRange10" with the variable set to e.g. 10, and another "InRange15", and so on.

    I want something more generic: I can attach the same Monobehaviour script to many game objects in my scene, and each "instance" will have it's own set of variables, I can configure through the inspector. In this way I can easily reuse scripts. If I subclass a new Condition, I just attach that to a condition GameObject in my tree, and the variables are shown in the inspector without having to write a new custom inspector .

    Has anyone encountered a graph, where I can attach scripts, and the graph node will then show the variables for me to configure?

    I'm considering using the animator controller, because I can attach scripts to each animator state, in the way that I mention above, but I'm having trouble accessing the "graph data" of the animator controller, e.g. outgoing transitions of an animation node. It would look like below. I can create nodes, transitions, and attach scripts to each node, where the data of the variables for the script will be local to that one node. Using the same script elsewhere can have different data for the variables

    UnityAI3.png

    Solutions to the above, or alternative ideas are very welcome. Thank you.