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.21k stars 369 forks source link

Scene/Prefab-based graphs #184

Open PeturDarriPeturs opened 2 years ago

PeturDarriPeturs commented 2 years ago

I want to be able to create graphs that are then saved as part of a scene or prefab. With BaseGraph inheriting ScriptableObject, that makes it difficult. ScriptableObjects can be saved as part of a scene, but not as part of a prefab.

Maybe BaseGraph can be redefined as a serializable class which then is serialized by ScriptableObject and MonoBehaviour wrappers with SerializeReference?

mfdeveloper commented 2 years ago

+1 👍🏾 @PeturDarriPeturs

I have the same requirement in my project. I would like the similar feature like this another package: xNode/Scene-Graphs

I tought that the script Examples/GraphBehaviour.cs will keep game objects and prefabs references, but the method BaseGraph.LinkToScene(scene) just automate the scene close when the graph window is closed 😢

@alelievr Could you help us?

alelievr commented 2 years ago

Yeah, it's a big limitation of the serialized ScriptableObject in a scene. The problem is that ScriptableObjects are really integrated into the logic of the code so you can't really remove them.

An alternative could be to serialize separately the nodes, parameters, edges, etc. of the graph directly inside the MonoBehaviour and when it's enabled create a graph ScriptableObject and assign the serialized data from the MonoBehaviour. I believe this can work with prefabs.

FYI, I plan to correctly integrate that for the V2 of NGP.