Open Appleguysnake opened 3 months ago
only INode can be connected / used without a problem, no other datatypes can be used as a port.
workarounds like generics don't make it possible either. (example below)
[Serializable, Node("200020ff", "types", createInputPort = false)]
public class FloatGraphNode : INode
{
[SerializeReference, Port(capacity = Capacity.Single, connectionPolicy = ConnectionPolicy.IdenticalOrSubclass, direction = PortDirection.Output)]
public Signal<float> output;
[SerializeReference, Port(capacity = Capacity.Single, connectionPolicy = ConnectionPolicy.IdenticalOrSubclass, direction = PortDirection.Input)]
public Signal<float> input;
}
[Node("200020ff", "types", createInputPort = false)]
public class Signal<T> : INode
{
public T value = default;
}
anyway it makes sense because NewGraph is only visual. Port is an attribute, it doesn't inherently allow you to communicate data. so it makes sense that the only thing you can connect together are other "INode"'s.
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
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
The errors:
InvalidOperationException
and fails. Saving the graph and trying to open it — or just recompiling code — throws the same error, and then throws anArgumentException
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.Case 1a: Value field on nested class
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:
Case 3: Changed data structure (crash)
NodeTest3
to inerit fromUnityEngine.Object
and keepINode
. (or anything Unity can serialize, I haven't tested everything)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 withSerializeReference
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.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.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.