Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

[Released] uNode - Visual Scripting [Support C# Import/Export]

Discussion in 'Assets and Asset Store' started by wahid_rachmawan, Oct 18, 2017.

  1. Deleted User

    Deleted User

    Guest

    that's so great.

    oh , I mean both
    like this
    Code (CSharp):
    1. private delegate void Something();
    2.  
    3.     private Something Test;
    4.  
    5.     void Start()
    6.     {
    7.         Test += TestFun;
    8.         Test();
    9.     }
    10.  
    11.     void TestFun()
    12.     {
    13.         Debug.Log("Test");
    14.     }
    15.    
    "Exception: Delegate is not supported"

    you konw , I can do this another way like using anonymousFun
    like
    Code (CSharp):
    1. Test += (something,something,something)
    2. {
    3.     TestFun(something,something,something);
    4. };
    it work
    but I still think there's better way to do this.
    MultipurposeNode?
    oh why this node can't be createo_O
     
  2. wahid_rachmawan

    wahid_rachmawan

    Joined:
    Oct 4, 2017
    Posts:
    512
    Creating new delegate type is currently not supported, you'll need to create it using c# and i think its very simple.
    And maybe you should use System.Action or System.Func and its generic type so you not need to create new delegate type.

    You can use Event Hook node, its more simple and easier.
    Capture.png

    The MultipurposeNode can't be created manually without target but its auto created when you're creating new node from the c# variable, property, function, event, type, and much more.
     
    Szaruga likes this.
  3. wahid_rachmawan

    wahid_rachmawan

    Joined:
    Oct 4, 2017
    Posts:
    512
    uNode v1.8.7 has been released.

    changelog v1.8.7:
    -Added ability to change node display ( Default, Partial, Full )
    -Added ability to inspect any element using 'Shift' + 'Left Click'
    -Improved Editor
    -Changed Type Patcher now only work on hitting 'Compile' button instead of 'Save' in playmode
    -Fixed graph can't keep changes on saving in play mode
    -Fixed some bugs

    Download here : http://maxygames.com/download/
     
    Szaruga likes this.
  4. Szaruga

    Szaruga

    Joined:
    Jan 29, 2016
    Posts:
    403
    @wahid_rachmawan
    Two problems (still in version 1.8.6):

    1. I can't add a variable to the script and modify the existing one or change their order at one time.
    example:
    I have three variables:
    - A (int)
    - B (string)
    - C (vector)
    if I add the fourth one (D - bool), I can't move it higher in order or change the type of others. After EVERY change I have to compile the script. So a separate compilation after adding the variable, separate after changing the type, separate after changing the order etc.

    The fact that you have to compile every now and then is not the worst yet. Problems start when I forget about it and errors occur - and their repair takes time and is annoying.
    I suspect that for novice users this can be very annoying.

    2. Self-resetting node "TryGetValue".
    It compiles well after use and the C # code is correct.
    However, any change in nodes causes the VALUE to be automatically reset to "null" values. This causes a constant need to re-set the reference before each compilation and also prevents the use of the "TryGetValue" node more than once in one script (since a change in one automatically resets the first settings)
    2020-05-10_14-18-55.png

    There is also a question of the "TryAdd" method that doesn't work at all - but it's probably the fault of Unity itself ...
     
  5. wahid_rachmawan

    wahid_rachmawan

    Joined:
    Oct 4, 2017
    Posts:
    512
    1. I have try it many times and still not see the bug happen, please send me a video or more detailed explanation for i can fix it.
    2. What are the TryGetValue 'Key' and 'Value' type? i've try it and it appear to be work correctly.

    Thanks for report it.
     
  6. Szaruga

    Szaruga

    Joined:
    Jan 29, 2016
    Posts:
    403
    Value.

    I'm sending a video showing problem number 2.

    I am currently undergoing major changes in the project, so I will show problem number 1 later.

    P.S.
    The scripts (uNode) that I work with and which I use to create C # code - I created over a year ago using old versions of uNode - maybe they contain some old rubbish that breaks something and if I created it again - there would be no such problems ( especially problem number 1)
     

    Attached Files:

  7. wahid_rachmawan

    wahid_rachmawan

    Joined:
    Oct 4, 2017
    Posts:
    512
    Thanks for send it, it will be fixed soon.
     
  8. Szaruga

    Szaruga

    Joined:
    Jan 29, 2016
    Posts:
    403
    A small suggestion:

    In the case of "Less Than Or Equal" and "Greater Than Or Equal" maybe it is worth adding one more line? --->
    2020-05-10_17-37-26.png

    P.S.
    Thanks for new uNode version. :)
     
    Last edited: May 10, 2020
  9. wahid_rachmawan

    wahid_rachmawan

    Joined:
    Oct 4, 2017
    Posts:
    512
    Thanks you for the suggestion but i think the current icon is more better because adding one more line will make the icon more small so its not worth when zooming out the graph.
     
    SwiftIllusion likes this.
  10. Szaruga

    Szaruga

    Joined:
    Jan 29, 2016
    Posts:
    403
    @wahid_rachmawan
    I noticed one more problem with self-resetting.
    When I have a list on the input of a function and set the value "null", after performing another action, or even after switching to another function - the value "null" resets to an empty list.

    2020-05-12_00-21-03.png
     
  11. wahid_rachmawan

    wahid_rachmawan

    Joined:
    Oct 4, 2017
    Posts:
    512
    Thanks for report it, it will be fixed in next update and you can temporary fix it by promoting the input into nodes
     
  12. Szaruga

    Szaruga

    Joined:
    Jan 29, 2016
    Posts:
    403
    Thanks.

    Will evolutionary changes in the direction of compactness of nodes continue?
    On the example of the picture - the nodes "IF", maybe "Return" and others that can be?
    2020-05-12_18-47-46.png

    One more small problem:
    When I choose the enum type and the default value appears, when compiling I have the value "Null". So even though the node looks good, I still need to manually correct / re-select the default value. A similar problem probably also applies to other types. --->
    2020-05-12_19-49-23.png
     
    Last edited: May 12, 2020
  13. wahid_rachmawan

    wahid_rachmawan

    Joined:
    Oct 4, 2017
    Posts:
    512
    Yes of course when i have created icon for that node to identify i'll make it compactness.

    Edit: you can change the display into Partial in the preference and more node will become compactness.

    Will be fixed in the next update.
     
    Last edited: May 14, 2020
    Szaruga likes this.
  14. DavidLe360

    DavidLe360

    Joined:
    Dec 24, 2018
    Posts:
    127
    Hi, i have a problem ( i posted on discord):

    Hi, i have this problem: the popup menu is sticker at the upper right corner:
    [2:58 PM]

    [3:01 PM]
    that happen when the unit 'Ui Scaling' setting is not 100%:


    thanks in advance
     
  15. Szaruga

    Szaruga

    Joined:
    Jan 29, 2016
    Posts:
    403
    I have a similar problem --->
    2020-05-14_22-35-07.png

    My screen resolution is 3840:2160 and UI scaling 150%.
     
  16. DavidLe360

    DavidLe360

    Joined:
    Dec 24, 2018
    Posts:
    127
    Yeap is the same problem. Did you find a work around? I don't wanna use UI scaling at 100%: things are too small.

    And i had it since previous Unode versions. Now i restart to use Unode and see that again.
     
  17. Szaruga

    Szaruga

    Joined:
    Jan 29, 2016
    Posts:
    403
    This is a bit problematic.
    I manage in two ways:

    1. I try to call the search window again (sometimes it helps).
    2. I use other calling methods. - e.g. directly at nodes. (closer to the left side of the screen).

    uNode is too valuable to give it up for that reason.
     
  18. DavidLe360

    DavidLe360

    Joined:
    Dec 24, 2018
    Posts:
    127
    hmm, i dont find it, what do u mean?
     
  19. wahid_rachmawan

    wahid_rachmawan

    Joined:
    Oct 4, 2017
    Posts:
    512
    Thanks for report, that bug will be fixed soon.
     
    Szaruga and DavidLe360 like this.
  20. Szaruga

    Szaruga

    Joined:
    Jan 29, 2016
    Posts:
    403
    Calling this window in uNode is possible in various ways. if I do it by, for example, pressing the space bar or clicking on nodes (closer to the left side of the screen) then the window appears closer and is visible all.
     
  21. DavidLe360

    DavidLe360

    Joined:
    Dec 24, 2018
    Posts:
    127
    Thank you. Space bar is awesome
     
  22. DavidLe360

    DavidLe360

    Joined:
    Dec 24, 2018
    Posts:
    127
    I installed the c# parser but doesn't see the menu to open the window.

    upload_2020-5-16_12-44-25.png

    I have the setting:
    upload_2020-5-16_12-43-48.png

    I think there is a conflict with other asset, bcz in an other project, it works
     
    Last edited: May 16, 2020
  23. wahid_rachmawan

    wahid_rachmawan

    Joined:
    Oct 4, 2017
    Posts:
    512
    Do you have any error in the console?
     
  24. DavidLe360

    DavidLe360

    Joined:
    Dec 24, 2018
    Posts:
    127
    oh yea, sorry, here are the errors:
    Code (CSharp):
    1. [Exception] PrecompiledAssemblyException: Multiple precompiled assemblies with the same name Microsoft.CodeAnalysis.CSharp.dll included or the current platform. Only one assembly with the same name is allowed per platform. Assembly paths:
    2. Assets/Battlehub/RTExtensions/RTScripting/CodeAnalysis/Plugins/Microsoft.CodeAnalysis.CSharp.dll
    3. Assets/uNode/Addons/C# Parser/Microsoft.CodeAnalysis.CSharp.dll
    4. EditorBuildRules.ValidateAndGetNameToPrecompiledAssembly()    <480b5a3bd3214ce5831f6dd8c68fdc55>:0
    5.  
    6. EditorBuildRules.ToScriptAssemblies()    <480b5a3bd3214ce5831f6dd8c68fdc55>:0
    7.  
    8. EditorBuildRules.GenerateChangedScriptAssemblies()    <480b5a3bd3214ce5831f6dd8c68fdc55>:0
    9.  
    10. EditorCompilation.CompileScripts()    <480b5a3bd3214ce5831f6dd8c68fdc55>:0
    11.  
    12. EditorCompilation.CompileScripts()    <480b5a3bd3214ce5831f6dd8c68fdc55>:0
    13.  
    14. EditorCompilation.TickCompilationPipeline()    <480b5a3bd3214ce5831f6dd8c68fdc55>:0
    15.  
    16. EditorCompilationInterface.TickCompilationPipeline()    <480b5a3bd3214ce5831f6dd8c68fdc55>:0
    17.  
    18. EditorCompilationInterface.TickCompilationPipeline()
    19.  
    Code (CSharp):
    1. [Exception] PrecompiledAssemblyException: Multiple precompiled assemblies with the same name Microsoft.CodeAnalysis.CSharp.dll included or the current platform. Only one assembly with the same name is allowed per platform. Assembly paths:
    2. Assets/Battlehub/RTExtensions/RTScripting/CodeAnalysis/Plugins/Microsoft.CodeAnalysis.CSharp.dll
    3. Assets/uNode/Addons/C# Parser/Microsoft.CodeAnalysis.CSharp.dll
    4. EditorBuildRules.ValidateAndGetNameToPrecompiledAssembly()    <480b5a3bd3214ce5831f6dd8c68fdc55>:0
    5.  
    6. EditorBuildRules.ToScriptAssemblies()    <480b5a3bd3214ce5831f6dd8c68fdc55>:0
    7.  
    8. EditorBuildRules.GetAllScriptAssemblies()    <480b5a3bd3214ce5831f6dd8c68fdc55>:0
    9.  
    10. EditorCompilation.GetAllScriptAssemblies()    <480b5a3bd3214ce5831f6dd8c68fdc55>:0
    11.  
    12. EditorCompilation.GetAllScriptAssemblies()    <480b5a3bd3214ce5831f6dd8c68fdc55>:0
    13.  
    14. CompilationPipeline.GetEditorAssemblies()    <480b5a3bd3214ce5831f6dd8c68fdc55>:0
    15.  
    16. CompilationPipeline.GetAssemblies()    <480b5a3bd3214ce5831f6dd8c68fdc55>:0
    17.  
    18. CompilationPipeline.GetAssemblies()    <480b5a3bd3214ce5831f6dd8c68fdc55>:0
    19.  
    20. CompilationPipeline.GetAssemblies()    <480b5a3bd3214ce5831f6dd8c68fdc55>:0
    21.  
    22. AssemblyNameProvider.GetAssemblies()    Library/PackageCache/com.unity.ide.rider@1.1.4/Rider/Editor/ProjectGeneration/ProjectGeneration.cs:60
    23. 58:   public IEnumerable<Assembly> GetAssemblies(Func<string, bool> shouldFileBePartOfSolution)
    24. 59:   {
    25. -->60:     return CompilationPipeline.GetAssemblies()
    26. 61:       .Where(i => 0 < i.sourceFiles.Length && i.sourceFiles.Any(shouldFileBePartOfSolution));
    27. 62:   }
    28.  
    29. ProjectGeneration.GenerateAndWriteSolutionAndProjects()    Library/PackageCache/com.unity.ide.rider@1.1.4/Rider/Editor/ProjectGeneration/ProjectGeneration.cs:297
    30. 295:   // Only synchronize islands that have associated source files and ones that we actually want in the project.
    31. 296:   // This also filters out DLLs coming from .asmdef files in packages.
    32. -->297:   var assemblies = m_AssemblyNameProvider.GetAssemblies(ShouldFileBePartOfSolution);
    33. 299:   var allAssetProjectParts = GenerateAllAssetProjectParts();
    34.  
    35. ProjectGeneration.Sync()    Library/PackageCache/com.unity.ide.rider@1.1.4/Rider/Editor/ProjectGeneration/ProjectGeneration.cs:223
    36. 221:   if (!externalCodeAlreadyGeneratedProjects)
    37. 222:   {
    38. -->223:     GenerateAndWriteSolutionAndProjects(types);
    39. 224:   }
    40.  
    41. ProjectGeneration.SyncIfNeeded()    Library/PackageCache/com.unity.ide.rider@1.1.4/Rider/Editor/ProjectGeneration/ProjectGeneration.cs:197
    42. 195:   if (HasFilesBeenModified(affectedFiles, reimportedFiles))
    43. 196:   {
    44. -->197:     Sync();
    45. 198:     return true;
    46. 199:   }
    47.  
    48. RiderScriptEditor.SyncIfNeeded()    Library/PackageCache/com.unity.ide.rider@1.1.4/Rider/Editor/RiderScriptEditor.cs:229
    49. 227:     string[] importedFiles)
    50. 228:   {
    51. -->229:     m_ProjectGeneration.SyncIfNeeded(addedFiles.Union(deletedFiles).Union(movedFiles).Union(movedFromFiles),
    52. 230:       importedFiles);
    53. 231:   }
    54.  
    55. CodeEditorProjectSync.PostprocessSyncProject()    <480b5a3bd3214ce5831f6dd8c68fdc55>:0
    56.  
    57. AssetPostprocessingInternal.PostprocessAllAssets()    <480b5a3bd3214ce5831f6dd8c68fdc55>:0
    58.  
     
  25. wahid_rachmawan

    wahid_rachmawan

    Joined:
    Oct 4, 2017
    Posts:
    512
    I think the rosyln library is confict with another asset, you can try removing one of those library ( Microsoft.CodeAnalisis.Csharp.dll ) either in uNode or other asset.
     
  26. DavidLe360

    DavidLe360

    Joined:
    Dec 24, 2018
    Posts:
    127
    I post this solution - about how to parse C# code, with ref parameter and uNode Spawner - here in case it could help other new user, like me :)

     
  27. DavidLe360

    DavidLe360

    Joined:
    Dec 24, 2018
    Posts:
    127
    There is lots of bugs, when working with FSM ... It even crash Unity (Unity 2019.3.13f1).

    Is it normal for this Unode version (1.8.7)?
     
    Last edited: May 21, 2020
  28. wahid_rachmawan

    wahid_rachmawan

    Joined:
    Oct 4, 2017
    Posts:
    512
    The last time i used FSM it's working fine, maybe because of the newers update may bring new bug in FSM. For the unity crash it may because of stack overflow when you are doing recursive state overtime without some wait action because when the state exit, it enter the new state dirrectly without waiting for the next frame. If you have any suggestion regarding FSM, please post it here, thanks.
     
    DavidLe360 likes this.
  29. DavidLe360

    DavidLe360

    Joined:
    Dec 24, 2018
    Posts:
    127
    I removed the one in uNode (Assets\uNode\Addons\C# Parser\Microsoft.CodeAnalysis.CSharp.dll) and is not solved: doesn't see the menu to open the window for C# parser

    Code (CSharp):
    1. [Error] Argument 1:
    2. cannot convert from 'System.Collections.Immutable.ImmutableArray<Microsoft.CodeAnalysis.Location>' to 'System.Collections.Generic.IEnumerable<Location>'
    3. [Error] Argument 1:
    4. cannot convert from 'System.Collections.Immutable.ImmutableArray<Microsoft.CodeAnalysis.Location>' to 'System.Collections.Generic.IEnumerable<Location>'
    5. [Error] Argument 1:
    6. cannot convert from 'System.Collections.Immutable.ImmutableArray<Microsoft.CodeAnalysis.Location>' to 'System.Collections.Generic.IEnumerable<Location>'
    7. [Error] Argument 1:
    8. cannot convert from 'System.Collections.Immutable.ImmutableArray<Microsoft.CodeAnalysis.Location>' to 'System.Collections.Generic.IEnumerable<Location>'
    9. [Error] Argument 1:
    10. cannot convert from 'System.Collections.Immutable.ImmutableArray<Microsoft.CodeAnalysis.Location>' to 'System.Collections.Generic.IEnumerable<Location>'
    11. [Error] Argument 1:
    12. cannot convert from 'System.Collections.Immutable.ImmutableArray<Microsoft.CodeAnalysis.Location>' to 'System.Collections.Generic.IEnumerable<Location>'
    13. [Error] 'Location' does not contain a definition for 'IsInSource' and no accessible extension method 'IsInSource' accepting a first argument of type 'Location' could be found (are you missing a using directive or an assembly reference?)
    14. [Error] Operator '==' cannot be applied to operands of type 'method group' and 'LocationKind'
    15. [Error] Argument 1:
    16. cannot convert from 'System.Collections.Immutable.ImmutableArray<Microsoft.CodeAnalysis.Location>' to 'System.Collections.Generic.IEnumerable<Location>'
    17. [Error] Argument 1:
    18. cannot convert from 'System.Collections.Immutable.ImmutableArray<Microsoft.CodeAnalysis.Location>' to 'System.Collections.Generic.IEnumerable<Location>'
    19. [Error] Argument 1:
    20. cannot convert from 'System.Collections.Immutable.ImmutableArray<Microsoft.CodeAnalysis.Location>' to 'System.Collections.Generic.IEnumerable<Location>'
    21. [Error] 'Location' does not contain a definition for 'IsInSource' and no accessible extension method 'IsInSource' accepting a first argument of type 'Location' could be found (are you missing a using directive or an assembly reference?)
    22.  
     
    Last edited: May 25, 2020
  30. wahid_rachmawan

    wahid_rachmawan

    Joined:
    Oct 4, 2017
    Posts:
    512
    What's the others plugin you're used?
     
  31. DavidLe360

    DavidLe360

    Joined:
    Dec 24, 2018
    Posts:
    127
    Logic Forge, Arbor 3, etc. Ohh, i know what to try: installing Unode first then adding the other then see witch one will cause Unode c#Parser to fail. Then i will tell you witch one

    Opps, are u asking witch uNode plugin?: the 'Vertical' One, witch works, and it's a great feature btw :)
     
  32. DavidLe360

    DavidLe360

    Joined:
    Dec 24, 2018
    Posts:
    127
  33. DavidLe360

    DavidLe360

    Joined:
    Dec 24, 2018
    Posts:
    127
    Question: in a uNode Runtime, how to call a method from an other uNode Runtime? Note that there is no generated code yet, only uNode Runtime graphs.

    For example, some thing like this:
    - Class A have methode Do() .
    public class A: MonoBehaviour {
    public Do() {
    // ...
    }
    }

    - Class B, in this Update() method, he want to call A.Do() .
    public class B: MonoBehaviour {
    void Start() {
    public A a;
    }

    Void Update() {
    a.Do();
    }
    }
     
    Last edited: May 27, 2020
  34. DavidLe360

    DavidLe360

    Joined:
    Dec 24, 2018
    Posts:
    127
    Hi, how to add 'CreateAssetMenu' Attribut for a Class? There is already 'CreateAssetMenuAsset' tho. Is almost the same but it seems It's not.
    upload_2020-5-27_7-51-53.png
     

    Attached Files:

  35. wahid_rachmawan

    wahid_rachmawan

    Joined:
    Oct 4, 2017
    Posts:
    512
    Hmm maybe SimpleSQL has some library that makes it conflict with the C# Parser, sorry i can't fix it because i don't have access to SimpleSQL the only one to access c# parser is to use it with the other project that doesn't have SimpleSQL.

    If your graph is in the scene you can follow the step bellow:
    1.gif

    It's like that, you only need to edit it by double-clicking it.
     
    DavidLe360 likes this.
  36. DavidLe360

    DavidLe360

    Joined:
    Dec 24, 2018
    Posts:
    127
    It was my fault :D: I did some thing, then after, I was enable to drag and drop a scriptableobject into a uNode grpah. To solve that: just 'reimport' the .cs file (Rclick on .cs file, then select 'reimport').
     
  37. drukengamer

    drukengamer

    Joined:
    Sep 17, 2018
    Posts:
    6
    Hi,

    I have some questions on State Graph, take a look at these screens of a very basic State Graph.



    And here is the rotate nodes within the RotateToTarget state:



    Very simple stuff, but when I compile the code I get complete spaghetti code..

    Have a look:
    Code (CSharp):
    1. using UnityEngine;
    2. using System.Collections.Generic;
    3.  
    4. public class StateTests : MonoBehaviour
    5. {
    6.     public GameObject FirstWaypoint = null;
    7.     public float flt_RotSpeed = 1F;
    8.     public Vector3 vec3_TargetDirection = Vector3.zero;
    9.     private float flt_ClampedRotSpeed = 0F;
    10.     private Quaternion quat_ToRotation = new Quaternion() { w = 1F };
    11.     public EventCoroutine coroutine1;
    12.     public EventCoroutine coroutine2;
    13.  
    14.     void Start()
    15.     {
    16.         coroutine1.Run();
    17.     }
    18.  
    19.     bool _ExecuteEvent(string name)
    20.     {
    21.         switch (name)
    22.         {
    23.             case "If_1":
    24.                 {
    25.                     if ((FirstWaypoint != null))
    26.                     {
    27.                         _ExecuteEvent("SetDirection");
    28.                     }
    29.                     else
    30.                     {
    31.                         _ExecuteEvent("DebugNull");
    32.                     }
    33.                 }
    34.                 break;
    35.             case "SetDirection":
    36.                 {
    37.                     vec3_TargetDirection = (FirstWaypoint.transform.position - base.transform.position); _ExecuteEvent("Node_15");
    38.                 }
    39.                 break;
    40.             case "DebugNull":
    41.                 {
    42.                     Debug.Log("Waypoint GameObject is null");
    43.                     _ExecuteEvent("StopCoRoutines");
    44.                 }
    45.                 break;
    46.             case "Node_15":
    47.                 {
    48.                     quat_ToRotation = Quaternion.LookRotation(vec3_TargetDirection, Vector3.up); _ExecuteEvent("Node_18");
    49.                 }
    50.                 break;
    51.             case "StopCoRoutines":
    52.                 {
    53.                     base.StopAllCoroutines();
    54.                 }
    55.                 break;
    56.             case "Node_18":
    57.                 {
    58.                     this.transform.rotation = Quaternion.Slerp(base.transform.rotation, quat_ToRotation, (Time.deltaTime * flt_RotSpeed)); _ExecuteEvent("Node_6");
    59.                 }
    60.                 break;
    61.             case "Node_6":
    62.                 {
    63.                     Debug.Log("Looking at Waypoint 1");
    64.                 }
    65.                 break;
    66.         }
    67.         return true;
    68.     }
    69.  
    70.     System.Collections.IEnumerable _ExecuteCoroutineEvent(string name)
    71.     {
    72.         switch (name)
    73.         {
    74.             case "RotateToTarget":
    75.                 {
    76.                     coroutine2.Run();
    77.                     _ExecuteEvent("If_1");
    78.                     while (coroutine1.state == null)
    79.                     {
    80.                         yield return null;
    81.                     }
    82.                 }
    83.                 break;
    84.             case "TransitionEvent":
    85.                 {
    86.                     yield return new WaitForSeconds(0.1F);
    87.                     coroutine1.Stop(true);
    88.                     yield return coroutine1.Run();
    89.                     break;
    90.                 }
    91.         }
    92.         yield break;
    93.     }
    94.  
    95.     void Awake()
    96.     {
    97.         coroutine1 = new EventCoroutine(this, _ExecuteCoroutineEvent("RotateToTarget"), () =>
    98.         {
    99.             coroutine2.Stop();
    100.         });
    101.         coroutine2 = new EventCoroutine(this, _ExecuteCoroutineEvent("TransitionEvent"));
    102.     }
    103. }
    One simple rotate to target resulted in 100 lines of code.

    I mainly use NodeCanvas for statemachines and behavior trees, but I thought I would try UNode since it exports C# code.

    But if I was to build some of the statemachines and behavior trees I've built in NodeCanvas in the past with this, I mean full NPC AI full patrol states sight sound detection, weapon switching, IK aiming etc etc etc..

    It would result in 10k lines of spaghetti code that would be impossible to follow or debug and maintain.

    So my question, is there a better way to setup state machines and behavior trees that results in cleaner code.

    Thanks in advance.
     

    Attached Files:

    DavidLe360 likes this.
  38. wahid_rachmawan

    wahid_rachmawan

    Joined:
    Oct 4, 2017
    Posts:
    512
    Hi Drukengamer,

    In State Graph every flow node is a State so they must have a return whether it success or failure and it can do recursive connection like the state node, this is why if you're working in state graph the generated c# code will become spaghetti like that and there's no way to fix it except a node that's not targeting recursive connection and a node that's connected to a node that's not get its state (regular flow node) or a nested node just like your RotateToTarget. uNode do have clean c# code export for the state graph in earlier version of uNode but i have remove it due to compatibility reason so when running graph in a reflection mode or c# it will have exactly same result, i don't have any reported issue about this so i think its should be fine to leave it as is. I can do bring this feature again when / after v1.9 stable released.
     
  39. drukengamer

    drukengamer

    Joined:
    Sep 17, 2018
    Posts:
    6
    Hi Wahid,

    Thanks for the quick reply.

    I think I found a solution, calling a function inside the state has much cleaner results.
    Also using actions seems to fold the code up as well.

    Heres a function call example:

    Code (CSharp):
    1. using UnityEngine;
    2. using System.Collections.Generic;
    3.  
    4. public class StateTests : MonoBehaviour {
    5.  
    6.     public GameObject FirstWaypoint = null;
    7.     public float flt_RotSpeed = 1F;
    8.     public Vector3 vec3_TargetDirection = Vector3.zero;
    9.     private Quaternion quat_ToRotation = new Quaternion() { w = 1F };
    10.     public EventCoroutine coroutine1;
    11.     public EventCoroutine coroutine2;
    12.  
    13.     private void TestingFunctions() {
    14.         flt_RotSpeed = 2;
    15.         if((FirstWaypoint != null)) {
    16.             vec3_TargetDirection = (FirstWaypoint.transform.position - base.transform.position);
    17.             quat_ToRotation = Quaternion.LookRotation(vec3_TargetDirection, Vector3.up);
    18.             this.transform.rotation = Quaternion.Slerp(base.transform.rotation, quat_ToRotation, (Time.deltaTime * flt_RotSpeed));
    19.             Debug.Log("Looking at Waypoint 1");
    20.         } else {
    21.             Debug.Log("Waypoint GameObject is null");
    22.             base.StopAllCoroutines();
    23.         }
    24.     }
    25.  
    26.     void Start() {
    27.         coroutine1.Run();
    28.     }
    29.  
    30.     bool _ExecuteEvent(string name) {
    31.         switch(name) {
    32.             case "TestingFunctions_21": {
    33.                 TestingFunctions();
    34.             }
    35.             break;
    36.         }
    37.         return true;
    38.     }
    39.  
    40.     System.Collections.IEnumerable _ExecuteCoroutineEvent(string name) {
    41.         switch(name) {
    42.             case "RotateToTarget": {
    43.                 coroutine2.Run();
    44.                 _ExecuteEvent("TestingFunctions_21");
    45.                 while(coroutine1.state == null) {
    46.                     yield return null;
    47.                 }
    48.             }
    49.             break;
    50.             case "TransitionEvent": {
    51.                 yield return new WaitForSeconds(0.1F);
    52.                 coroutine1.Stop(true);
    53.                 yield return coroutine1.Run();
    54.                 break;
    55.             }
    56.         }
    57.         yield break;
    58.     }
    59.  
    60.     void Awake() {
    61.         coroutine1 = new EventCoroutine(this, _ExecuteCoroutineEvent("RotateToTarget"), () => {
    62.             coroutine2.Stop();
    63.         });
    64.         coroutine2 = new EventCoroutine(this, _ExecuteCoroutineEvent("TransitionEvent"));
    65.     }
    66. }
     
    wahid_rachmawan likes this.
  40. wahid_rachmawan

    wahid_rachmawan

    Joined:
    Oct 4, 2017
    Posts:
    512
    Glad to hear that you found the solution:).
     
  41. wahid_rachmawan

    wahid_rachmawan

    Joined:
    Oct 4, 2017
    Posts:
    512
    uNode v1.9 BETA 1 has been released.

    What's New:

    New Class Component graph and Class Asset graph:
    The new graphs allow you to run it in runtime just like uNode Runtime does but this can’t be created in the Scene but it have an advantage over uNode Runtime like the the new graphs can be referenced by the others graph without performing compilation like the video below:


    You can attach Class Component graph to a component on a game object in the scene just like MonoBehaviour in c#
    Below is how to make it:
    drag_to_add_spawner.gif

    And the new Class Asset graph can be attached to an asset file in your project just like ScriptableObject in c#. This is useful to create data classes. In order to create the instance of the graph you can right click on the asset graph or any folder and choose ‘Create Instance’, below is how to do it:
    creating_asset_instance.gif

    Please note that the new graphs is depend on uNode so if you want to generate script without depend on uNode you can use uNode Class or uNode Struct as it generate pure c# or if you very want new graph don't depend on uNode you can do by modifying the new graph script inherit type from a 'RuntimeBehavior' to 'MonoBehaviour'

    Auto C# Code Generation on Build
    With the auto c# code generation on build your runtime graph whether is Class Component, Class Asset, or uNode Runtime will run as fast as native c# script on build and if you want to get the same performance in the editor like in the build you can do it manually by clicking new menu in 'Tools > uNode':
    • Generate C# Scripts
      This will compile all project graphs into c# scripts with exception manually compiled graph will be skipped.
      This is used to auto generate script on build.
    • Generate C# including Scenes
      This will compile all project graphs into c# script and will find all graph in all scene in build settings into c# scripts
    • Delete Generated C# Scripts
      Using this menu will remove all generated script and your graph will run with the reflection system.
      Please note that this will remove all files in the folder 'uNode.Generated' so please don't place anything in this folder.
    And there's 3 C# Code Generation options that you can change in preference:
    • Default
      Using individual graph setting, when the graph setting is also default this will be performed in Performance mode
    • Performance
      Generate pure c# and get the best result in term of performance but it may give errors when other graph is not compiled into script, the performance mode mean that the generated script is all pure c# so no more reflection system is used.
    • Compatibility
      Generate c# script that's compatible with all graph even when other graph is not compiled into script, the compatibility mode will use a small of reflection system only to get / set the others graph data so if your graph don't referencing others graph the generated script should be same as performance mode.
      There's some graph that use this mode by default:
      -uNode Runtime
      -uNode Class
      -uNode Struct
      All those graph is using compatibility mode because it's not guarantee that the referenced of the other graph has been compiled and it's because those graph can be individually compiled into script.
    The refactoring features is missing for the new feature but is still in WIP and will be available before the stable version out.

    Sorry i have tired so i can't give you more detail info about all the new features but you can guess in the changelog.

    changelog v1.9b1:
    -New uNode Class Asset a new graph that's work just like ScriptableObject and can be run without need to compile into script
    -New uNode Asset Instance a instance of a new Class Asset graph just like asset of a ScriptableObject
    -New uNode Class Component a new graph that's work just like MonoBehaviour and can be run without need to compile into script
    -New Runtime Type that's created from a Class Component or Class Asset graph and can be used for referencing a graph
    -Now uNode will auto generate c# script on build so the exported game will have native c# performance and supporting of all target platform
    -Added ability to convert graph into another graph type
    -Added ability to convert node into block by dragging the node into block nodes
    -Added preferred display value to choose the display of input port inside or outside node
    -Added preference to set up generation mode: Default, Performance, or Compatibility
    #Default: using individual graph setting and force to be pure when the graph use default setting
    #Performance: generate pure c# and get the best in term of performance but it may give errors when other graph is not compiled into script
    #Compatibility: generate c# script that's compatible with all graph even when other graph is not compiled into script​
    -Added new menu to compile all graphs into c# script
    #Tools > uNode > Generate C# Scripts - will compile all project graphs into c# scripts with exception manually compiled graph will be skipped
    #Tools > uNode > Generate C# including Scenes - compile all project graphs and will find all graph in all scene in build settings into c# scripts​
    -Improved CSharpParser
    -Improved CSharpGenerator
    -Improved Graph Inspector
    -Improved Item Selector
    -Improved uNode Editor
    -Improved uNodeSpawner, now it can run graph using c# script when the target graph has been compiled into c# and supporting new Class Component graph
    -Major code refactoring and its now include full source code
    -Moved most c# generation setting from individual to global setting
    -Moved the minimum required version of Unity to 2019.1
    -Removed Horizontal / Native graph theme and makes the Vertical graph to be default graph
    -Fixed most of knowed and reported bugs

    Download here : http://maxygames.com/download/

    Please read it here carefully for updating to new version: http://maxygames.com/docs/unode/installing_and_updating/

    Please note that the uNode now required Unity 2019.1 and Scripting Runtime Version : .NET 4.x Equivalent.
     
    Last edited: May 31, 2020
  42. DavidLe360

    DavidLe360

    Joined:
    Dec 24, 2018
    Posts:
    127
  43. sledgeman

    sledgeman

    Joined:
    Jun 23, 2014
    Posts:
    389
    Hey. Great Update.
    I downloaded it, and tried it with U 5.6. But uNode v1.9b1 seems not to work anymore with my unity version. This error appears :
    Assets/uNode/TransitionEvent/OnTriggerExit2D.cs(23,37): error CS1644: Feature `type pattern matching' cannot be used because it is not part of the C# 4.0 language specification

    and 200+ errors related to C# 4.0 thing. Is there any chance to make it work again with U 5.6 ? Thx.
     
  44. wahid_rachmawan

    wahid_rachmawan

    Joined:
    Oct 4, 2017
    Posts:
    512
    Sorry for late answer.

    Its a new bug, do you have any errors in the console?
    And thanks for report it.

    Sorry but start in v1.9 uNode no longer support U5.6 because i need a newer c# language to made improvement more easy and less time.

    Like this upcoming feature in the next update:

    uNode now collect the full graph information when generating c#, i have made an improvement bellow by using this information:

    Improved C# Preview:

    With this feature you can learn or see how the c# are generated by which nodes, functions, properties and variables.
    And you can click on the script and the source from which the script was generated will be highlighted.

    Unity Console Integration:


    With this feature you can now easy find any error, info, or warning in the graph by selecting the log and uNode will highlight the nodes at the correct location, this feature work with / without debug mode it mean it's work with pure c# script.
    This feature only highlight Flow node because the Log only provides the line number without column number in the script log but its still very useful for example fixing a bug.
     
    Last edited: Jun 3, 2020
  45. sledgeman

    sledgeman

    Joined:
    Jun 23, 2014
    Posts:
    389
    Thx for the clarification. Can understand it, because of "newer c# language" ...
     
  46. Szaruga

    Szaruga

    Joined:
    Jan 29, 2016
    Posts:
    403
    I created a new empty project with uNode 1.9 beta. When I unpack the C# Parser, I get the following errors:
    IllcxA9.png

    edit//
    Unity 2019.3.15f1
     
    Last edited: Jun 4, 2020
  47. wahid_rachmawan

    wahid_rachmawan

    Joined:
    Oct 4, 2017
    Posts:
    512
    I think i forget to pack the c# parser, and i think the c# parser is included in that version so you don't need to import it.
     
  48. wahid_rachmawan

    wahid_rachmawan

    Joined:
    Oct 4, 2017
    Posts:
    512
    uNode v1.9 BETA 2 has been released.

    changelog v1.9b2:
    -New Unity Console Intergration: when running using generated script whatever with debug mode or not, clicking any log in the Console (info, warning, or error) will highlight the flow node and when running using runtime graph and an error was throw, clicking on the error log will highlight the node that is throw the errors
    -Improved CSharpGenerator
    -Improved C# Preview: It is now possible to click on the script and select & highlight the nodes, variables, properties, and functions that's generating the script
    -Improved Graph Editor Performance: Now uNode will cache the node views instead of refreshing it every time when doing an action
    -Fixed some bug
    -Fixed some warning

    Download here : http://maxygames.com/download/
     
    Szaruga and Innocent-Dev like this.
  49. Szaruga

    Szaruga

    Joined:
    Jan 29, 2016
    Posts:
    403
    Test:
    New project ---> Unity 2019.3.15f1 + uNode 1.9 BETA 2


    I copied my uNode test prefab for the project. I used the "Fix Missing Script" option.

    Then I opened this prefab and started to browse.
    There was such an error --->
    2020-06-07_14-11-35.png
    And weird looking nodes --->
    2020-06-07_14-23-05.png
     
  50. wahid_rachmawan

    wahid_rachmawan

    Joined:
    Oct 4, 2017
    Posts:
    512
    It may because of cache view made that bug, i have stuck a few day before to fix many bug when making cache feature so a new bug may appear but you can manually hit refresh button to force the graph use new node views.

    Do you mean the black separator make weird look?