alelievr / NodeGraphProcessor

Node graph editor framework focused on data processing using Unity UIElements and C# 4.6
https://github.com/alelievr/NodeGraphProcessor/projects/2
MIT License
2.34k stars 387 forks source link

Script recompile and entering play mode is causing a null reference exception #128

Closed emrys90 closed 3 years ago

emrys90 commented 3 years ago

Anytime scripts recompile or I enter play mode, I get this exception:

System.NullReferenceException: Object reference not set to an instance of an object at GraphProcessor.NodePort.CreatePushDataDelegateForEdge (GraphProcessor.SerializableEdge edge) [0x00034] in C:\Projects\Tests\NodeGraphProcessorTest\Packages\com.alelievr.NodeGraphProcessor\Runtime\Elements\NodePort.cs:191 UnityEngine.Debug:LogError(Object) GraphProcessor.NodePort:CreatePushDataDelegateForEdge(SerializableEdge) (at Packages/com.alelievr.NodeGraphProcessor/Runtime/Elements/NodePort.cs:220) GraphProcessor.NodePort:Add(SerializableEdge) (at Packages/com.alelievr.NodeGraphProcessor/Runtime/Elements/NodePort.cs:155) GraphProcessor.NodePortContainer:Add(SerializableEdge) (at Packages/com.alelievr.NodeGraphProcessor/Runtime/Elements/NodePort.cs:356) GraphProcessor.BaseNode:OnEdgeConnected(SerializableEdge) (at Packages/com.alelievr.NodeGraphProcessor/Runtime/Elements/BaseNode.cs:536) GraphProcessor.BaseGraph:Deserialize() (at Packages/com.alelievr.NodeGraphProcessor/Runtime/Graph/BaseGraph.cs:456) GraphProcessor.BaseGraph:OnEnable() (at Packages/com.alelievr.NodeGraphProcessor/Runtime/Graph/BaseGraph.cs:168)

Any ideas how to resolve this? Am I doing something wrong?

emrys90 commented 3 years ago

I figured out the issue for this. CreatePushDataDelegateForEdge in NodePort does reflection for public fields only, while my fields were private with a SerializeField attribute. I added BindingFlags.NonPublic to the flags and I no longer get this error.

alelievr commented 3 years ago

Hello, thanks for investigating this issue, this should be fixed with https://github.com/alelievr/NodeGraphProcessor/commit/8e93c04143d4c5a793a07357a0f10782b658eabc