Git Product home page Git Product logo

newgraph's Introduction

NewGraph

UnityVersion Version GitHub last commit GitHub GitHub issues image NewGraph is a data-oriented node graph solution for Unity powered by UIToolkit (UIElements). This is based on the idea to visualize complex data structures as graph networks without having to modify already established data classes, except adding [Node], [Port], [PortList] and [SerializeReference] attributes to all classes that should show in the Graph View.

This is planned to receive long term support as it is an integral part of our internal suite of tools at Gentlymad Studios.

Changelog 📢

See the Changelog for current updates!

Requirements 🌵

  1. GraphViewBase
  2. OdinSerializer (Original OdinSerializer repository: https://github.com/TeamSirenix/odin-serializer)
  3. This project requires UnityVersion (or later) as the Unity version.

Features 🍒

  • WYSIWYG. A port connecting to a node in the graph is a real reference to the object in your graph .asset
  • Good performance even with many nodes as this is built upon the new retained UIToolkit UI system.
  • create visual data oriented networks based on your custom [Serializable] data classes simply by adding attributes.
  • Fully serialized dynamic lists of ports with the [PortList] attribute.
  • Customize data visualization with [GraphDisplay]: Display a field inside the graph, side inspector or both views.
  • Full support of Unity's native Undo/Redo stack.
  • Support for Utility Nodes that can be created to help organize your specific graph business.
  • Copy & Paste even across graphs.
  • No child ScriptableObject mayhem! A graph asset will hold all your data in one single scriptable object.
  • Cyclic references and complex reference chains are natively supported with the use of [SerializeReference] attribute.
  • No reliance on the now deprecated Experimental.GraphView. Everything was written from scratch or is based on maintainable code.
  • Keyboard shortcuts, a searchable context menu, default UtilityNodes like CommentNode, GroupCommentNode, a extensively commented code base and more...

Wiki 📒

See the Wiki for installation & usage instructions.

~ Use at your own risk. ~

newgraph's People

Contributors

doppelkeks avatar leissler avatar whippetsaintdogs avatar wolverwin avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

newgraph's Issues

Unhandled errors corrupt graph data and sometimes crash editor

There are a few related errors I've been dealing with while learning my way around NewGraph. I'm grouping them here because they're related and hopefully have some common point where they can all be caught together.

Main issue

When there's a problem with the use of attributes or saved graph data, the graph data can sometimes be unrecoverable resulting in cases where a lot of work can be lost due to a typo or other simple mistake.

Sometimes on recompile the graph window is cleared completely and the errors in the console give little indication of what actually went wrong so it's hard to tell where the error came from.
In some cases the nodes load, but can't be used and the graph seems to load thousands of invisible nodes. In others, the only way to fix the graph is to delete it and recreate it from scratch.

Case 1 : Simple Value fields

Using this code

[Serializable, Node]
public class NodeTest2 : INode
{
	[SerializeReference, Port]
	public float num;
}

Adding a single node to a new empty graph results in the node being created and no errors in the console. It can be moved around and assigned as a reference to another node's output without issue. But trying to delete it throws an InvalidOperationException and fails.
Saving the graph and trying to open it — or just recompiling code — throws the same error, and then throws an ArgumentException every update.
The result looks like this. Only one node was added, the others are from trying to drag it. The node count in the inspector is from a box selection, which matches the count of console errors. It appears a new node is added every time even though loading the data failed.
2024-04-04 10_07_39-NewGraph
The errors:

InvalidOperationException: managedReferenceValue is only available on fields with the [SerializeReference] attribute
UnityEditor.SerializedProperty.get_managedReferenceValue () (at <80a8ce1980c648dca8e68f0d8aa3b930>:0)
NewGraph.GraphController+<>c__DisplayClass43_0.<Load>b__2 (GraphViewBase.BaseNode node) (at Assets/NewGraph/Editor/Controllers/GraphController.cs:503)
NewGraph.GraphView.ForEachNodeDo (System.Action`1[T] callback) (at Assets/NewGraph/Editor/Views/GraphView.cs:117)
NewGraph.GraphController+<>c__DisplayClass43_0.<Load>b__0 () (at Assets/NewGraph/Editor/Controllers/GraphController.cs:497)
UnityEngine.UIElements.VisualElement+SimpleScheduledItem.PerformTimerUpdate (UnityEngine.UIElements.TimerState state) (at <332857d8803a4878904bcf8f9581ec33>:0)
UnityEngine.UIElements.TimerEventScheduler.UpdateScheduledEvents () (at <332857d8803a4878904bcf8f9581ec33>:0)
UnityEngine.UIElements.UIElementsUtility.UnityEngine.UIElements.IUIElementsUtility.UpdateSchedulers () (at <332857d8803a4878904bcf8f9581ec33>:0)
UnityEngine.UIElements.UIEventRegistration.UpdateSchedulers () (at <332857d8803a4878904bcf8f9581ec33>:0)
UnityEditor.RetainedMode.UpdateSchedulers () (at <cc76bab7efe9480f901125fd04a708b6>:0)
ArgumentException: An item with the same key has already been added. Key: NodeTest2
System.Collections.Generic.Dictionary`2[TKey,TValue].TryInsert (TKey key, TValue value, System.Collections.Generic.InsertionBehavior behavior) (at <27124aa0e30a41659b903b822b959bc7>:0)
System.Collections.Generic.Dictionary`2[TKey,TValue].Add (TKey key, TValue value) (at <27124aa0e30a41659b903b822b959bc7>:0)
NewGraph.GraphController+<>c__DisplayClass43_0.<Load>g__ForEachNodeProperty|1 (System.Collections.Generic.List`1[T] nodes, UnityEditor.SerializedProperty nodesProperty) (at Assets/NewGraph/Editor/Controllers/GraphController.cs:483)
NewGraph.GraphController+<>c__DisplayClass43_0.<Load>b__0 () (at Assets/NewGraph/Editor/Controllers/GraphController.cs:489)
UnityEngine.UIElements.VisualElement+SimpleScheduledItem.PerformTimerUpdate (UnityEngine.UIElements.TimerState state) (at <332857d8803a4878904bcf8f9581ec33>:0)
UnityEngine.UIElements.TimerEventScheduler.UpdateScheduledEvents () (at <332857d8803a4878904bcf8f9581ec33>:0)
UnityEngine.UIElements.UIElementsUtility.UnityEngine.UIElements.IUIElementsUtility.UpdateSchedulers () (at <332857d8803a4878904bcf8f9581ec33>:0)
UnityEngine.UIElements.UIEventRegistration.UpdateSchedulers () (at <332857d8803a4878904bcf8f9581ec33>:0)
UnityEditor.RetainedMode.UpdateSchedulers () (at <cc76bab7efe9480f901125fd04a708b6>:0)

Case 1a: Value field on nested class

[Serializable, Node]
public class NodeTest2 : INode
{
	public NodeTestValue next;
}
[Serializable, Node]
public class NodeTestValue : INode
{
	[SerializeReference, Port]
	public float num;
}

Case 2: UnityEngine.Object

Same as above (probably the same for anything unity can serialize). Only notable because the errors are less clear than if you try to make a node from a monobehavior (see #41). Code used:

[Serializable, Node]
public class NodeTest2 : INode
{
	[SerializeReference, Port]
	public NodeTestValue next;
}
public class NodeTestValue : MonoBehaviour, INode { }

Case 3: Changed data structure (crash)

  • Create a two node graph with the code below
  • Change NodeTest3 to inerit from UnityEngine.Object and keep INode. (or anything Unity can serialize, I haven't tested everything)
  • Recompile changes in Unity
[Serializable, Node]
public class NodeTest2 : INode
{
	[SerializeReference, Port]
	public NodeTest3 something;
}
[Serializable, Node]
public class NodeTest3 : INode 
{
	public object obj;
}

2024-04-04 11_07_06-NewGraph
The result is similar to above, with the same two errors, but with an additional one that happens every inspector update as long as the gameobject with the MonoGraphModel component is open, even when the graph window is closed.
Update: This appears to be thrown by Unity if you assign an object to an interface field with SerializeReference on it, but not while the field is null. Not sure why it's being thrown in this situation since there's no interface field being drawn in the inspector.

Fields with [SerializeReference] cannot serialize objects that derive from Unity.Object, in this case: Assembly-CSharp NodeTest3

In this case, the editor crashed when trying to reopen the graph. The same might happen with the other bugs and might be a result of how many nodes were created but I don't have time to test that in detail right now.

Case 4: Null properties

I unfortunately have to go so I can't finish figuring out the exact reproduction steps, but I have a file with more console errors related to null references and things. But you probably get the gist by now.

For this one I modified GraphController to catch null properties, but it's just a quick fix for the constant loading null nodes, it doesn't actually allow the graph to load the non-corrupt nodes.

void ForEachNodeProperty(List<NodeModel> nodes, SerializedProperty nodesProperty) {
                    // go over every node...
                    for (int i = 0; i < nodes.Count; i++) {
                        NodeModel node = nodes[i];

			if(node.nodeData == null)
			{
				Debug.LogError("Trying to load null nodeData. Probably an attribute error");
				return;
			}

                        // initialize the node...
                        node.Initialize();

The values to handle are here https://docs.unity3d.com/ScriptReference/Serialization.ManagedReferenceUtility.html

Expected behavior

I don't know UIToolkit enough to know what's reasonable to expect or implement, but anything that avoids having to delete the graph data (or manually edit the .asset file) would be a huge improvement.

Implement sub-graphs

The feature of sub-graphs is such a common feature for the better organization of graphs in many graph-based tools, that it could be a standard feature of such a system. Probably real subgraphs are more than just implementing another utility like the GroupComment node (but I'm not sure). Subgraphs have their own "ports" that interface the subgraph and look to the parent class like a node.

Programmatically Created Ports Do Not Save

I added a NewGraph.ContextMenu and called GraphSearchWindowProvider.AddNodeEntry to add a context menu option with an Action. In the action I am programmatically creating my nodes and ports and connecting them. Also adding VisualElements to the NodeView. All are generated fine, however, after making any changes GraphController.Load(IGraphModel graphModel) is called and seems to wipe out all my changes. I even added a call to GraphController.EnsureSerialization() to ensure serialization of the changes, but they do not persist. I am using a custom data class that inherits from INode and is decorated with the necessary attributes. Could you help with this?

Size of Node-Creation Menu not correct

When the list of possible nodes gets long and scrolls inside the menu, then sometimes the bottom gets cut off.
Here's an example:
image

Also in cases with no scrolling, the text is extremely tight (if not cut off a pixel) at the bottom.
image

Clumsy to connect existing node with edge to a new node

When I want to connect a node with an existing output edge to a newly created node's input port, I first have to delete the edge and can then drag a new one to the new node.
Expected: Drag an edge from the existing output port to the new node's input port replaces the existing edge.

Enable code to reference input port

I assumed this would be possible but wasn't able to find any way to do it or to hack it in myself easily. Hopefully I didn't miss something obvious.

Comments on #6 and #34 make it seem like the input port is just meant to be a place to connect output ports as a reference for those fields to the node. However, a very simple use case that would fit within the intended design is a doubly-linked list, where a child node has a reference to its parent. Even if this was limited to single-connection input ports that would be very useful.

The example node is just a classic linked list node with data, next, and prev. Hypothetically in NewGraph it would look like:

[Serializable, Node(inputPortCapacity: Capacity.Single)]
public class LinkedNode : INode
{
	[GraphDisplay(DisplayType.BothViews)]
	Object data;

	[InputPort]  //A separate attribute for clarity, but conceptually the same as 
                     //[Port(direction = PortDirection.Input, capacity = Capacity.Single)]
	[SerializeReference]
	LinkedNode prev;

	[SerializeReference, Port]
	LinkedNode next;
}

With the attribute on prev, when an output port is connected, the prev field would be set to the node that connected to it. If there was no input port attribute, it would behave as it does now.

PortDirection.Input doesn't set properties and deletes edges

Since the direction parameter was added I thought it would be possible to just hide the default input port and create a replacement to implement linked lists, but on entering play mode or deleting an edge, all edges connecting to custom input ports are deleted from the graph. When connected to a port list, the name of the list entry doesn't change, it seems the underlying property is never actually set.

Using Unity 2022.3.22

PortList only accepts type INode

Hi again,
I have been using this graph a lot over the last few weeks, as it is amazing! Very easy to use, and extend upon.

However, I am finding an issue with the use of PortList, in that it only renders in the UI if the type of the list is List

As mentioned in my other ticket (#34) I am a base implementation of INode named CoreNode that all my other nodes derive from.

I am implementing resource/value nodes, so that I can have nodes that target / retrieve values when queried by a connected node.

After abandoning my attempt at input nodes (see other issue), I have been using output ports to connect to my value nodes. This is working well for value nodes with a single return / reference. However, I am now trying to implement value nodes that take a collection. For example, I have VNode_Vector3 that returns a single Vector3 value. However, I also want to have VNode_Vector3Collection. This would have a list of ports that would go out to a number of VNode_Vector3 ports.

However, if I implement it like the following, it does not render:
[PortList, SerializeReference]
public List<VNode_Vector3> valueNodes;

I have tried with a number of different classes, all deriving from INode either directly or via parents, and the only way I can get the port list to render is if I do the following:
[PortList, SerializeReference]
public List valueNodes;

This puts the burden of casting to the appropriate type onto the node when it is fetching values, and does not allow me to block connections from incompatible nodes.

Is there a method of implementation that I am not aware of, and if not could this please be considered for a future fix?
Thanks!

Graph inspector showing multiselect message depite one node selected

If you select 2 (or more) nodes, the inspector will correctly show a message that multiple nodes are selected.
However, when you deselect all nodes but one, the message is still there, claiming that multiple nodes are selected (the number in the message also doesn't change when deselecting).
The expected behavior is that the inspector shows the node's contents as soon as only one node is selected, even if multiple were selected before.

Low rendering efficiency by OnGUI()

I see that NewGraph's UI element are still rendered by EditorWindow OnGUI() method,it means it has the same issue like IMGUI about low rendering efficiency(draw every frame),Have you ever wondering how to improve that?

No `Tools/GraphWindow` in the toolbar

I have added OdinSerializer and GraphViewBase in package manager, and clone the NewGraph repo in Asset Folder. It compiles fine with no error or warning, but when I goto Wiki of Usage General Usage, I can't find Tools/GraphWindow in my toolbar(I only see Tools/Odin Serializer).General Usage 📒
I don't know why.

Doesn't work in 2022.3

problem: newgraph doesn't show up under tools.

how to reproduce:

  1. create a new project
  2. follow the official instructions on unity version 2022.3

Make context menu items configurable

If such a system should be usable across many cases, the context menu in the graph window needs to be customizable. Although it always makes sense to have a “Create Node” item in the menu, several others should be configurable and custom entries addable.

List field in Inspector does not update until node reopened

First of all, thank you for this package it made development so much easier for me!

When adding or removing an entry in a List that is shown in the Inspector the change does not appear until I tab out and back into the Node again!

I am using the latest version (0.4.2)!

Deleting graph while graph window is open throws errors

Pretty obvious what went wrong when this happens, but errors are thrown every update so it seems like it should be handled in some way.

Repro

  • Create a graph (I used MonoGraphModel) and open it
  • Add a node
  • Delete the graph component

Result: this error is thrown until the window is closed

SerializedObject target has been destroyed.
UnityEngine.StackTraceUtility:ExtractStackTrace ()
NewGraph.NodeModel:SetPosition (single,single) (at Assets/NewGraph/Models/NodeModel.cs:174)
NewGraph.NodeController:SetPosition (single,single) (at Assets/NewGraph/Editor/Controllers/NodeController.cs:67)
NewGraph.NodeView:SetPosition (UnityEngine.Vector2) (at Assets/NewGraph/Editor/Views/NodeView.cs:313)
GraphViewBase.GraphElement:ApplyDeltaToPosition (UnityEngine.Vector2) (at ./Library/PackageCache/com.gentlymad.graphviewbase@9e7e3c3574/Editor/Elements/Graph/GraphElement.cs:128)
GraphViewBase.GraphElementContainer:HandleDrag (GraphViewBase.DragEvent,GraphViewBase.BaseNode) (at ./Library/PackageCache/com.gentlymad.graphviewbase@9e7e3c3574/Editor/Elements/GraphElementContainer.cs:208)
GraphViewBase.GraphElementContainer:OnDrag (GraphViewBase.DragEvent) (at ./Library/PackageCache/com.gentlymad.graphviewbase@9e7e3c3574/Editor/Elements/GraphElementContainer.cs:202)
UnityEngine.GUIUtility:ProcessEvent (int,intptr,bool&)

Expected result

I'm not sure what the preferred / simplest way to handle this would be. When deleting open scenes in Unity, the behavior is that the scene is marked dirty and you're asked if you want to save it whenever you close it or the editor. Just closing the graph window would make sense as well. Catching the error and throwing a message to tell the user to close the window also seems fine.

Nodes are forced to have an input port

In my use-case of a visual scripting system, there is a requirement to have so-called event nodes that have no input ports but only one (or potentially more) output ports. Right now this is not possible, as one input port is always present. Just like output ports, the input ports could be definable using the port attribute on a variable with a given type.

Closing/re-opening project ScriptableGraphModel.asset not found

Produced in Unity 2023.2.3.16f1
Upon closing and re-opening project the AssetDatabase appears to lose the reference to the ScriptableGraphModel.asset with the following error:

settings blueprint could not be resolved! Path: Assets/Scripts/Editor/NewGraph/Editor/Settings/GraphSettings.asset GUID: 015778251503b3c44a2b9dfc3a36ad10
UnityEngine.Debug:LogError (object)
NewGraph.GraphSettingsSingleton:get_BlueprintSettings () (at Assets/Scripts/Editor/NewGraph/Editor/Settings/GraphSettingsSingleton.cs:34)
NewGraph.GraphSettingsSingleton:get_Settings () (at Assets/Scripts/Editor/NewGraph/Editor/Settings/GraphSettingsSingleton.cs:55)
NewGraph.GraphWindow:InitializeWindowBase (System.Type) (at Assets/Scripts/Editor/NewGraph/Editor/Views/GraphWindow.cs:80)
WindowInitializer.WindowInitializer:OpenWindow () (at Assets/Scripts/Editor/JobClassGraph/WindowInitializer.cs:12)

WindowInitializer was moved out of the Sample folder to a Scripts > Editor folder but has been unchanged:

namespace WindowInitializer {
	public class WindowInitializer {
		/// <summary>
		/// Here you can customize where the graph window menu should appear
		/// </summary>
		[MenuItem("Tools/" + nameof(GraphWindow))]
		static void OpenWindow() {
			// Here you can define what type of graph model you would like to use.
			GraphWindow.InitializeWindowBase(typeof(ScriptableGraphModel));
		}
	}
}

Any help appreciated!

Double-click on GraphModel asset does not open graph

With a GraphWindow open and double-clicking on a GraphModel-asset that is not currently shown (or alternatively clicking the open button in the Unity-Inspector), the new GraphModel-asset is not opened in the existing window.
Even though there is a "Load" button in the GraphView itself, this would be expected behavior.

Port Capacity.Multiple not working correctly, being overwritten by newest connection

I recently added this package to our project and ran into an issue with the multiple port connection property. We have an output node with Capacity.Multiple, however when we connect this to multiple nodes, only the last connection is serialized and the rest are lost whenever the graph is reloaded (or the domain is recompiled). Is there something we are missing?

Edit: this only seems to apply to output nodes. Is it possible to use Capacity.Multiple on outputs, or would this need to be a PortList?

Graph flickers when deleting nodes

When deleting a node or edge, the whole graph disappears/flickers for a split second. That is a bit irritating and does not exactly help make the system more trustworthy to users. Is that really necessary?

Enter Playmode Settings generates errors

When using the following combo of "Enter Playmode Settings"
image

a MonoGraphModel on a GameObject throws the following error when the GraphWindow is open and entering Play Mode in the editor:
ArgumentException: Object at index 0 is null
UnityEditor.SerializedObject..ctor (UnityEngine.Object obj) (at /Users/bokken/build/output/unity/unity/Editor/Mono/SerializedObject.bindings.cs:22)
NewGraph.GraphModelBase.CreateSerializedObject (UnityEngine.Object scope, System.String rootFieldName) (at Assets/NewGraph/Models/GraphModelBase.cs:147)
NewGraph.MonoGraphModel.CreateSerializedObject () (at Assets/NewGraph/Models/MonoGraphModel.cs:61)
NewGraph.MonoGraphModel.get_BaseObject () (at Assets/NewGraph/Models/MonoGraphModel.cs:44)
NewGraph.GraphSettings.SetLastOpenedGraphData (NewGraph.IGraphModelData graphData) (at Assets/NewGraph/Editor/Settings/GraphSettings.cs:35)
NewGraph.GraphController+<>c__DisplayClass43_0.b__0 () (at Assets/NewGraph/Editor/Controllers/GraphController.cs:452)
UnityEngine.UIElements.VisualElement+SimpleScheduledItem.PerformTimerUpdate (UnityEngine.UIElements.TimerState state) (at /Users/bokken/build/output/unity/unity/ModuleOverrides/com.unity.ui/Core/VisualElementScheduler.cs:346)
UnityEngine.UIElements.TimerEventScheduler.UpdateScheduledEvents () (at /Users/bokken/build/output/unity/unity/ModuleOverrides/com.unity.ui/Core/Scheduler.cs:363)
UnityEngine.UIElements.UIElementsUtility.UnityEngine.UIElements.IUIElementsUtility.UpdateSchedulers () (at /Users/bokken/build/output/unity/unity/ModuleOverrides/com.unity.ui/Core/UIElementsUtility.cs:253)
UnityEngine.UIElements.UIEventRegistration.UpdateSchedulers () (at /Users/bokken/build/output/unity/unity/ModuleOverrides/com.unity.ui/Core/UIElementsUtility.cs:105)
UnityEditor.RetainedMode.UpdateSchedulers () (at /Users/bokken/build/output/unity/unity/ModuleOverrides/com.unity.ui/Editor/RetainedMode.cs:55)

With a ScriptableGraphModel this works fine and without errors.

No entry point when cloning repo

Having the same issue as #31 but the new docs are confusing because the installation instructions say don't use the package manager. Old revisions of the usage info don't explain how to define your own entry point either.

If the Unity bug has been resolved (I wasn't able to find it on the issue tracker) then the installation instructions should be updated. Otherwise, the usage instructions should be updated. That part might be good to do anyway.

For anyone else with the issue, you can just change the name of the Samples~ folder to Samples and Unity will recognize it

New user questions

Hey there! Just found your project via the NGP discord. Had a few questions about it before driving in 🙂

  • Can we change the side of the node a port is attached to from horizontal to vertical?
  • Are there sub graphs, or an intention to add them?
  • Does the node editor this work at runtime? Being based on GraphViewPlayer it seems like it should, but you also seem to use assets for serialization, so maybe not?
  • And... do you have a discord or other community for asking these kind of questions? Sorry if I'm asking in the wrong place!

Choosing "None" value in a nodes GameObject-type field does not properly refresh the field

When having a node-field of a Unity-scene-reference type (e.g. a GameObject variable for referencing Prefabs) with either DisplayType.NodeView or DisplayType.BothViews in its GraphDisplay attribute, it is correctly possible to choose a value from Unity's selector box. However, when choosing the "None" value, the field in the node does not update to the correct value but instead stays at the last selected non-empty value.
With DisplyType.BothViews enabled, the field with the open selector box has this faulty behavior, while the other corresponding field (inspector or nodeview) does update correctly.

test5

The video shows that de-selecting the node and then selecting it correctly refreshes the value of the field.

Add a minimap feature

For many node-based tools, it is very important for users to be able to quickly pan along a graph and keep an overview of its structure. Although there is a "center viewport" button, it is far better supported by an interactive Minimap, which is not only by chance one of the most used navigation features in such tools. In large graphs, this is a lifesaver for everyday work.

Callback on value change

I'm trying to change node background depending on a variable, this makes things easier for me. But sadly I can't find a callback to hook, I'm currently using graph callback so if I click anything that is not a field it will be triggered

[CustomNodeEditor(typeof(RoomNode))]
public class RoomNodeEditor : NodeEditor
{
    private void Recolor(NodeController nodeController)
    {
        RoomNode room = nodeController.nodeItem.nodeData as RoomNode;
        nodeController.nodeView.style.backgroundColor = room.roomType switch
        {
            RoomNode.RoomType.Start => Color.green,
            RoomNode.RoomType.Hub => Color.white,
            RoomNode.RoomType.Normal => Color.gray,
            RoomNode.RoomType.MiniBoss => new Color(1, 0.682f, 0.125f),
            RoomNode.RoomType.Reward => Color.yellow,
            RoomNode.RoomType.Boss => Color.red,
            _ => throw new NotImplementedException(),
        };
    }

    public override void Initialize(NodeController nodeController)
    {
        Recolor(nodeController);

        //nodeController.graphController.graphView.OnAction += (action, obj) => { Recolor(nodeController); };
        nodeController.graphController.graphView.OnMouseDown += (mouseInput) => { Recolor(nodeController); };
        nodeController.graphController.graphView.OnAction += (action, obj) => { Recolor(nodeController); };
    }
}

It would be useful for this and similar features to have a callback for when any property of the node changes

Leak detected message after recompiling project

Right at the first domain reload, the following message appears in the console (working with MonoGraphModel):

Leak Detected : Persistent allocates 4 individual allocations.

When setting Preferences > Jobs > Leak Detection Level to "Enabled with Stack Trace", it produces the following extended message:

Found 4 leak(s) from callstack:
 #0  (Mono JIT Code) [PortView.cs:21] NewGraph.PortView:.ctor (NewGraph.PortInfo,UnityEditor.SerializedProperty,System.Action)
 #1  (Mono JIT Code) [NodeController.cs:102] NewGraph.NodeController:DoForEachPortProperty (System.Action`2<NewGraph.PortInfo, UnityEditor.SerializedProperty>)
 #2 ???
 #3 UnsafeUtility::Malloc(long long, int, NativeCollection::Allocator, ScriptingExceptionPtr*)
 #4 ???
 #5 ???
 #6 ???
 #7 ???
 #8 ???
 #9 ???
 #10 ???
 #11 mono_threads_enter_gc_unsafe_region_internal
 #12 ???
 #13 ???
 #14 ???
 #15 mono_thread_interruption_checkpoint_request
 #16 ???
 #17 ???
 #18 ???
 #19 ???

Implement optional "manual saving" to avoid performance issues for prefab use cases

Currently, MonoGraphModels can have a large overhead/ perormance degradation if the main gameobject contains a lot of components or is very complex in nature. There is nothing we can do about this fact (as it is completely individual and user driven) but we can implement manual saving to avoid saving and keeping the serializedobject up to date automatically.

Implement additional inputs

Hi! I'm trying to make a system similar as to what can be seen in ShaderGraph, where you create 'value' nodes that can feed into your main nodes to provide variables and context.

My current setup is as follows (see relevant scripts at the bottom):

I have created a 'CoreNode' class that derives from INode. In this, I have added methods for tracking outputs and executing actions. All of my nodes derive from this CoreNode.

The focus here is my ANode_SetAnimParameter class. It takes a string for the parameter name, and a string for the parameter value that is then parsed depending to an enum value (to parse as float, int or bool).

My goal was to change the parameter value string into its own node that feeds into the set anim parameter node.

To do this I did the following:

  • Created a class ValueNode that defines a property "Value" of type T, and a protected virtual method GetValue that is used to feed the Value getter.
  • Created a node class VNode_String : Value, that defines a public string value, that it feeds to an override of GetValue.
  • Added my standard [SerializeReference, Port] public CoreNode output to feed it to the target node.
  • Added a [SerializeReference, Port] public VNode_String valueInput; to the ANode_SetAnimParameter class.

To all first appearances, this seems to work. The ports are created properly, I can create the string node correctly, and connect them all up. However, as soon as I press play in the editor, the connections between the VNode_String nodes and the ANode_SetAnimParameter nodes are lost. All other connections maintain their links.

Any ideas why this is happening? I think maybe due to my use of the VNode_String type to the input port, however I do want to be able to restrict the port type so I dont accidently provide an int to a string input.

Appreciate your time / thoughts!
VNode_String.txt
ANode_SetAnimParameter.txt
CoreNode.txt
ValueNode.txt

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.