Exposing fields with graph API

Hello, I’m trying to create a Graph editor for a few of my systems, using Unity’s GraphView and have zero prior experience with it.

The thing is, I’m planning to use arbitrary classes as nodes, just exposing pins and their arguments by ‘marking’ them with custom attributes (for example, [GraphField] for configuration member variables, [InputPin] and [OutputPin] for some methods, corresponding to input and output functions, or something like that).

Ongoing plan is to store individual nodes in the corresponding “graph object” as kay-value pairs of object type name (System.Type.FullName) and the object data as Json-Serialized field, deserializing everything and reconstructing the logic when entering the play mode.

Problem is, that I don’t exactly want to be particularly specific about the ‘allowed’ types of the fields and want have a system that handles them without my involvement (ei something like the default inspector behavior, but per node). One thing that would likely work would be to have a way to create SerializedObjects by hand and somehow draw their properties on nodes or even the inspector window (graph would be preferred, but anyway), but so far I have no clue how to do it, nor do I have any knowledge of better alternatives.

Any help would be appreciated :slight_smile:

You probably want to start by looking at editor scripting; from the very vague image I have right now, you’ll probably get the best mileage out of declaring a few top-level nodes, and all nodes must derive from them. Create the editor scripts for the top level nodes.

1 Like

Thanks for suggestion :). Thing is, that I was planning to have a single ScriptableObject that stores all those instances alongside the connections, regardless of their type (Yes, they are supposed to be derived from the same class, but I did not think of a proper way to store abstract instances in a single asset without manual serialization). Your message reminded me that I have an option to store those instances as Sub-Assets of the graph file, expose the pins according to the original idea and implement just a single custom editor that simply shows exclusively the properties marked as fields (Of course, that would mean that I don’t get to show the exposed properties in the GraphView, but that ‘sacrifice’ is tolerable).

However, that’s still a multi-file solution and I’m not entirely sure I’ll be going for it.