Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

xNode - A general purpose node editor

Discussion in 'Assets and Asset Store' started by Siccity, Oct 30, 2017.

  1. Siccity

    Siccity

    Joined:
    Dec 7, 2013
    Posts:
    255
    NodeEditor.GetEditor(myNode, NodeEditorWindow.current);

    Heights are calculated dynamically from the contents of the node. For convenience the sizes (including width) is stored in NodeEditorWindow.current.nodeSizes. Note that these values can be one frame behind due to the values updating after the node draws.
    What you're doing looks correct. Maybe the problem is with serialization? Try calling serializedObject.Update after connecting the ports
    This isn't really xNode related. Try https://docs.unity3d.com/ScriptReference/SerializedProperty-arraySize.html
     
    hanbekov likes this.
  2. ununion

    ununion

    Joined:
    Dec 2, 2018
    Posts:
    268
    hi Siccity ,Is there any way I can use xNode without scriptableobject but like a EditorWindow open from menu?
     
  3. Siccity

    Siccity

    Joined:
    Dec 7, 2013
    Posts:
    255
    You can possibly open the window using [MenuItem] attribute on a static function that opens the NodeEditorWindow, but you won't get far without ScriptableObjects, as that's the cornerstone of xNode
     
  4. ununion

    ununion

    Joined:
    Dec 2, 2018
    Posts:
    268
    fine,thanks for your helping!
     
  5. Stacklucker

    Stacklucker

    Joined:
    Jan 23, 2015
    Posts:
    82
    Hi,

    loving the tool so far, but duplicating nodes doesn't seem to work properly if using scene graphs, since the scriptable object is being serialized in the monobehaviour it sits on, which Unity then claims is not persistent.



    Interestingly enough, selecting multiple nodes (or a single one) still lets me duplicate ONE node.

    Anyone have any input on this?
     
  6. charles1202

    charles1202

    Joined:
    Jan 19, 2020
    Posts:
    1
    Hi Siccity

    I am trying to change the color of a node based on a boolean that is instantiated on the node.
    Essentially when the boolean is set to true, I want the node to be blue.
    When it is set to false, I want the node to be red.

    I see GetBodyStyle on NodeEditor, and I created my own custom Texture and GUIStyle in NodeEditorResources.

    I was having trouble checking a variable on the node at the time the node's GUIStyle is chosen/updated.

    I was initially focusing in the NodeEditorGUI script in the DrawNodes function.
    I was not having much luck though.

    Any insight?
     
  7. RedBambooLeaf

    RedBambooLeaf

    Joined:
    Mar 22, 2020
    Posts:
    2
    Hi, thank you for the awesome features this system provides!

    I would like to use Odin serialized fields inside a node: I made the XNode.Node inherit from SerializedScriptableObject (Sirenix) instead of the Unity counterpart and it just works flawlessly with one exception, Output/Input fields.

    If I try to use the Output attribute along with the combo <NonSerialized, OdinSerialize> attributes on a field then the target object obtained from the serialized property passed to the PropertyField (NodeEditorGUILayout) method results in a null element when casted to XNode.Node.

    I tried to adapt the code to work but I'm not enough familiar with serialization, drawers etc.
    So, is there a way to make Odin Serialized fields work as Output(s)?

    This is the output field declaration:
    Code (CSharp):
    1. [NonSerialized, OdinSerialize, Output(dynamicPortList = true)] public Choice[] choices;
    - Choice is a Serializable Class with no inheritance which uses fields which cannot be serialized by Unity (Odin can serialize such fields)
    - if the Output attribute is removed, the field is correctly displayed/serialized but the output ports are not displayed
    - if OdinSerialize or NonSerialized attribute is removed, the field won't be serialized/showed correctly but the output ports are displayed

    This is the error displayed in console:
    NullReferenceException: Object reference not set to an instance of an object
    XNodeEditor.NodeEditorGUILayout.PropertyField (UnityEditor.SerializedProperty property, UnityEngine.GUIContent label, System.Boolean includeChildren, UnityEngine.GUILayoutOption[] options) (at Assets/xNode-master/Scripts/Editor/NodeEditorGUILayout.cs:26)
    XNodeEditor.OutputAttributeDrawer.DrawPropertyLayout (UnityEngine.GUIContent label) (at Assets/xNode-master/Scripts/Editor/Drawers/Odin/OutputAttributeDrawer.cs:41)
    Sirenix.OdinInspector.Editor.OdinDrawer.CallNextDrawer (UnityEngine.GUIContent label) (at Y:/Repositories/sirenix-development-framework/Sirenix Solution/Sirenix.OdinInspector.Editor/Drawers/OdinDrawer.cs:155)
    Sirenix.OdinInspector.Editor.Drawers.NullableReferenceDrawer`1[T].DrawPropertyLayout (UnityEngine.GUIContent label) (at Y:/Repositories/sirenix-development-framework/Sirenix Solution/Sirenix.OdinInspector.Editor/Drawers/Misc Drawers/NullableReferenceDrawer.cs:104)
    Sirenix.OdinInspector.Editor.OdinDrawer.CallNextDrawer (UnityEngine.GUIContent label) (at Y:/Repositories/sirenix-development-framework/Sirenix Solution/Sirenix.OdinInspector.Editor/Drawers/OdinDrawer.cs:155)
    Sirenix.OdinInspector.Editor.Drawers.FixUnityNullDrawer`1[T].DrawPropertyLayout (UnityEngine.GUIContent label) (at Y:/Repositories/sirenix-development-framework/Sirenix Solution/Sirenix.OdinInspector.Editor/Drawers/Misc Drawers/FixUnityNullDrawer.cs:87)
    Sirenix.OdinInspector.Editor.OdinDrawer.CallNextDrawer (UnityEngine.GUIContent label) (at Y:/Repositories/sirenix-development-framework/Sirenix Solution/Sirenix.OdinInspector.Editor/Drawers/OdinDrawer.cs:155)
    Sirenix.OdinInspector.Editor.Drawers.ReferenceDrawer`1[T].DrawPropertyLayout (UnityEngine.GUIContent label) (at Y:/Repositories/sirenix-development-framework/Sirenix Solution/Sirenix.OdinInspector.Editor/Drawers/Misc Drawers/ReferenceDrawer.cs:118)
    Sirenix.OdinInspector.Editor.OdinDrawer.CallNextDrawer (UnityEngine.GUIContent label) (at Y:/Repositories/sirenix-development-framework/Sirenix Solution/Sirenix.OdinInspector.Editor/Drawers/OdinDrawer.cs:155)
    Sirenix.OdinInspector.Editor.Drawers.PropertyContextMenuDrawer`1[T].DrawPropertyLayout (UnityEngine.GUIContent label) (at Y:/Repositories/sirenix-development-framework/Sirenix Solution/Sirenix.OdinInspector.Editor/Drawers/Misc Drawers/PropertyContextMenuDrawer.cs:659)
    Sirenix.OdinInspector.Editor.OdinDrawer.CallNextDrawer (UnityEngine.GUIContent label) (at Y:/Repositories/sirenix-development-framework/Sirenix Solution/Sirenix.OdinInspector.Editor/Drawers/OdinDrawer.cs:155)
    Sirenix.OdinInspector.Editor.Drawers.OdinSerializeAttributeWarningDrawer.DrawPropertyLayout (UnityEngine.GUIContent label) (at Y:/Repositories/sirenix-development-framework/Sirenix Solution/Sirenix.OdinInspector.Editor/Drawers/Attribute Drawers/OdinSerializeAttributeWarningDrawer.cs:95)
    Sirenix.OdinInspector.Editor.OdinDrawer.DrawProperty (UnityEngine.GUIContent label) (at Y:/Repositories/sirenix-development-framework/Sirenix Solution/Sirenix.OdinInspector.Editor/Drawers/OdinDrawer.cs:109)
    Sirenix.OdinInspector.Editor.InspectorProperty.Draw (UnityEngine.GUIContent defaultLabel) (at Y:/Repositories/sirenix-development-framework/Sirenix Solution/Sirenix.OdinInspector.Editor/Core/InspectorProperty.cs:831)
    Rethrow as OdinPropertyException: This error occurred while being drawn by Odin.
    Current IMGUI event: repaint
    Odin Property Path: choices
    Odin Drawer Chain:
    > OdinSerializeAttributeWarningDrawer
    > PropertyContextMenuDrawer<Choice[]>
    > ReferenceDrawer<Choice[]>
    > FixUnityNullDrawer<Choice[]>
    > NullableReferenceDrawer<Choice[]>
    > OutputAttributeDrawer
    > CollectionDrawer<Choice[]>
    > CompositeDrawer.
    UnityEngine.Debug:LogException(Exception)
    Sirenix.OdinInspector.Editor.InspectorProperty:Draw(GUIContent) (at Y:/Repositories/sirenix-development-framework/Sirenix Solution/Sirenix.OdinInspector.Editor/Core/InspectorProperty.cs:908)
    Sirenix.OdinInspector.Editor.InspectorProperty:Draw() (at Y:/Repositories/sirenix-development-framework/Sirenix Solution/Sirenix.OdinInspector.Editor/Core/InspectorProperty.cs:719)
    Sirenix.OdinInspector.Editor.Drawers.UnityObjectRootDrawer`1:DrawPropertyLayout(GUIContent) (at Y:/Repositories/sirenix-development-framework/Sirenix Solution/Sirenix.OdinInspector.Editor/Drawers/Value Drawers/UnityObjectRootDrawer.cs:60)
    Sirenix.OdinInspector.Editor.OdinDrawer:DrawProperty(GUIContent) (at Y:/Repositories/sirenix-development-framework/Sirenix Solution/Sirenix.OdinInspector.Editor/Drawers/OdinDrawer.cs:109)
    Sirenix.OdinInspector.Editor.InspectorProperty:Draw(GUIContent) (at Y:/Repositories/sirenix-development-framework/Sirenix Solution/Sirenix.OdinInspector.Editor/Core/InspectorProperty.cs:831)
    Sirenix.OdinInspector.Editor.PropertyTree:DrawProperties() (at Y:/Repositories/sirenix-development-framework/Sirenix Solution/Sirenix.OdinInspector.Editor/Core/PropertyTree.cs:499)
    Sirenix.OdinInspector.Editor.PropertyTree:Draw(Boolean) (at Y:/Repositories/sirenix-development-framework/Sirenix Solution/Sirenix.OdinInspector.Editor/Core/PropertyTree.cs:388)
    XNodeEditor.NodeEditor:OnBodyGUI() (at Assets/xNode-master/Scripts/Editor/NodeEditor.cs:62)
    XNodeEditor.NodeEditorWindow:DrawNodes() (at Assets/xNode-master/Scripts/Editor/NodeEditorGUI.cs:489)
    XNodeEditor.NodeEditorWindow:OnGUI() (at Assets/xNode-master/Scripts/Editor/NodeEditorGUI.cs:30)
    UnityEngine.GUIUtility:processEvent(Int32, IntPtr, Boolean&)
     
  8. antonkudin

    antonkudin

    Joined:
    Aug 4, 2014
    Posts:
    32
    Is this a known issue? Reorderable list of strings causes issues with two or more nodes. 2022-08-06 01-28-05.2022-08-06 01_29_11.gif
     
  9. MediaGiant

    MediaGiant

    Joined:
    Sep 14, 2013
    Posts:
    304
    Siccity likes this.
  10. X3doll

    X3doll

    Joined:
    Apr 15, 2020
    Posts:
    33
    Hey! @Siccity, first of all thank you for this magnificent piece of art. I'm using XNode for my graph solution because offer the max flexibility in less time possible.

    I was wrapping my head in this thing:

    upload_2023-4-5_15-27-41.png

    How did you put the icons inside? I didn't find any example in the internet.
    I Was trying to do it with Horizontal Layout but without success... Any tips?
     
    Siccity likes this.
  11. Siccity

    Siccity

    Joined:
    Dec 7, 2013
    Posts:
    255
    I did not make that, but you can use https://docs.unity3d.com/ScriptReference/GUI.DrawTexture.html and supply your own rect coordinates, placing it anywhere :D
     
  12. Dominicjan

    Dominicjan

    Joined:
    Sep 5, 2012
    Posts:
    9
    Hey. Thanks for xnode. Using this for my own dialogue solution, works great. However it's not very fast. if I would grow the dialogue even more it gets lower than 2 fps. What would be a way to optimize it? Amplify Shader seems similar and has no optimization issues
     

    Attached Files:

  13. SpookyCat

    SpookyCat

    Joined:
    Jan 25, 2010
    Posts:
    3,685
    Mmm odd I have much more complex scenes which also have some nodes with custom inpsector that creates meshes every frame and draws them in a node and not seeing any real slow down. What are your system specs?
    Screenshot 2023-09-05 232616.png