Seneral / Node_Editor_Framework

A flexible and modular Node Editor Framework for creating node based displays and editors in Unity
https://nodeeditor.seneral.dev
MIT License
2.01k stars 415 forks source link

Strange canvas #150

Closed RomanZhu closed 6 years ago

RomanZhu commented 6 years ago

Hi

I have canvas with serialized links to the scene. I save it to the scene. But, when i enter play mode on the same scene it's different canvas. To get my links back I need to manually load my canvas from the scene (or press reload canvas) (saving to assets menu lines are commented)

What to do? Is there a way to draw exactly saved canvas?

122

https://pastebin.com/Maj1dmxf

RomanZhu commented 6 years ago

It saves Lists and strings, but brakes link to scene, so i think it uses assets somehow (even tho that canvas is saved to scene)

RomanZhu commented 6 years ago

Well, i tested it in empty scene with slightly modified flow node and it works fine.. hmmm...

Seneral commented 6 years ago

Hi! Can't exactly follow what exactly is wrong for you when you say it's not the same canvas... Scene references should be maintained, I did test it well enough... Will check it out once I'm back home.

RomanZhu commented 6 years ago

Wtf, i copied whole nodeEditor folder to empty project and everything works o_o

RomanZhu commented 6 years ago

Yeah, links to gameObjects/lights are working fine. BUT links to custom components (even to NodeCanvasSceneSave) are broken when i enter play mode

I can get away with referencing GameObjects and getting component. BUT it won't work for cases where it's needed to have multiple components of same type on one object

RomanZhu commented 6 years ago

Just checked it with clear version of editor. (develop branch)

How to reproduce: 1)Create public field with custom type; 2)Draw something = (Blah)EditorGUILayout.ObjectField(something, typeof(Blah), true); 3)Set those references 4)Save to scene 5)Enter playmode

Seneral commented 6 years ago

Alright, will test it out:)

RomanZhu commented 6 years ago

Well, there are strange things.

1)References inside nodes survive after script recompilation, but not after entering playmode. 2)References inside simple ScriptableObject, who is sitting in some monobeh at scene can survive both of those domain changes, but nodes can not :(

Seneral commented 6 years ago

Ok, so these should be enough clues to get me started now:) Only now I saw the gif, was on mobile first... Unfortunately I did not come to check it out today, will have to take a look tomorrow.

Seneral commented 6 years ago

Ok, just verified this:) I'll take a lok at this now!

Seneral commented 6 years ago

Ok, got a bit side-tracked (Vegetation Studio Release lol) but I think I found the cause (assumption) and I have a fix for it.

Basically, before entering playmode, it saves the cache as it should, but then suddenly looses the canvas reference. I can only assume it has to do with the canvas being stored in the scene or something. Anyway, it automatically reloads the canvas, which works, BUT the references to the scene are broken as you experienced. This all happens before the actual playmode loading process, or atleast in an early phase. Previously, that loaded canvas (reaction to canvas loss) in the loading phase was then maintained since the canvas was not detected to be missing. This resulted in the faulty canvas being kept...

I decided to let the routine automatically fetch the canvas as before, even if that means the canvas is broken for a split second, until the playmode has finished loading. Now, here I added a call to automatically re-fetch the cached canvas, so it now re-loads it from the cache (which was saved before entering the playmode) after entering playmode.

That does work fine, however, I'd ultimately like to find a way to not loose the canvas before the playmode has actually changed...

I'll push that fix for now though, and see how well it works for you:) Seneral

RomanZhu commented 6 years ago

Thank you, i will test it once i finish project (one or two working days), don't want to break it :D

If you interested i could share example of fetching scene and parsing UnityEvents to create interactive network of nodes to be included into examples

Seneral commented 6 years ago

Good idea, would love to see how it works, definitely sounds interesting! :) Do you have a screen to show yet? Thanks

RomanZhu commented 6 years ago

zyz61ijlsd2q9x3pik40ga Reactions.zip

It's all fully interactive canvas, code is bad, i'll refactor (maybe, lol) Wires are basically unityEvents

There is 2 special kind of nodes for 2 main components with heavy custom editors (and dynamic knob count changing by observing component. It can mark by color when nodes are executing

Also there is reflection based generic node to show when anything references those 2 heavy components (it can parse even default Button events and change them using reflection)

I will add another kind of node to show when there is single field in component with reference to those 2 components (any serializeble fields with those types)

RomanZhu commented 6 years ago

It wont work for you, but you can see how i do things

Maybe later i will polish that generic node and canvas to be included into examples

Seneral commented 6 years ago

Wow, does look cool. As you said, won't work for me, but excited to see it nevertheless:) Reminded me of updating some older examples that use similar tech though:)

RomanZhu commented 6 years ago

I was asked to make a video about nodes, so i decided to post it here also :) https://youtu.be/i8Z05LX6OO8 https://youtu.be/PIWNZG4ez-Q

Seneral commented 6 years ago

Wow looks cool:) One suggestion: Overide DrawNodePropertyEditor and put the actual editing of reactions there to prevent overly large nodes. So, in the node you only have the options to list and connect reactions aswell as adding and removing them, then in the property editor (wich is displayed in the inspector when selecting the node) you can expand and edit the reactions properly. Apart from that, really nice, love to see a relatively complex use case working fine (apart from multi editing...) :)

RomanZhu commented 6 years ago

Thank you, without yours framework it would be very hard to do in time-limits, if possible

It was one of requested features to edit every value inside node :(

Seneral commented 6 years ago

Ah ok, no problem:) Although it is common practice by lots of professional tools to outsource the heavy property panels to a separate window focussing on the selected node. But it's up to anyone to decide for themselves of course:)

RomanZhu commented 6 years ago

Yep, it would be way easier to manage amount of knobs if i would manage addition and subtraction of reactions.. c: