Search Unity

  1. Looking for a job or to hire someone for a project? Check out the re-opened job forums.
    Dismiss Notice
  2. Unity 2020 LTS & Unity 2021.1 have been released.
    Dismiss Notice
  3. Good news ✨ We have more Unite Now videos available for you to watch on-demand! Come check them out and ask our experts any questions!
    Dismiss Notice

Help Wanted Create custom Unit

Discussion in 'Visual Scripting' started by Bastienre4, Mar 26, 2021.

  1. Bastienre4

    Bastienre4

    Joined:
    Jul 8, 2014
    Posts:
    138
    Hello!

    I have trouble creating a custom Unit.

    upload_2021-3-26_22-26-44.png

    However, I can't find the node in the search bar

    upload_2021-3-26_22-28-48.png

    I have no assemblies (I tried adding assemblies but it does not work neither).

    Did I missed something?
     
  2. ericb_unity

    ericb_unity

    Unity Technologies

    Joined:
    Nov 24, 2017
    Posts:
    58
    Bastienre4 likes this.
  3. Bastienre4

    Bastienre4

    Joined:
    Jul 8, 2014
    Posts:
    138
    I've already tried clicking on Regenerate Units but it still don't appear.
     
  4. ericb_unity

    ericb_unity

    Unity Technologies

    Joined:
    Nov 24, 2017
    Posts:
    58
    If you have no errors, it should normally be showing in your fuzzy finder in the first level of items.
     
  5. Bastienre4

    Bastienre4

    Joined:
    Jul 8, 2014
    Posts:
    138
    I have no errors. I'm using Unity 2021.1.0f1 and the package 1.6.0-pre.3.
    I had the package in 1.5.2 before that with the same issue.
    upload_2021-3-29_21-30-0.png
    I don't know what could be wrong...
     
  6. ericb_unity

    ericb_unity

    Unity Technologies

    Joined:
    Nov 24, 2017
    Posts:
    58
    Tried with this code and it generate well.
    upload_2021-3-29_16-35-57.png

    Code (CSharp):
    1. using Unity.VisualScripting;
    2.  
    3. public class TestNode : Unit
    4. {
    5.     [DoNotSerialize]
    6.     public ValueInput myValueA; // Adding the ValueInput variable for myValueA
    7.     protected override void Definition()
    8.     {
    9.         myValueA = ValueInput<string>("myValueA", "Hello ");
    10.     }
    11. }
     
  7. JasonJonesLASM

    JasonJonesLASM

    Joined:
    Sep 5, 2012
    Posts:
    223
    I'm not 100% sure on the specific behavior, but you must have some port or or inspectable value available in the script as a variable. Why I do not know. Was always this way. But you don't have one, and Eric does and it's working. So I'm assuming that's the reason. Probably how they are found during the query operation when generating. Skipping stuff without them.
     
    Bastienre4 likes this.
  8. tigme

    tigme

    Joined:
    Jul 1, 2014
    Posts:
    11
  9. tigme

    tigme

    Joined:
    Jul 1, 2014
    Posts:
    11
    Example of my first attempt to make a custom unit

    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4. using System;
    5. using Unity.VisualScripting;
    6.  
    7. [UnitCategory("Poems Nodes/JSON")]
    8. [UnitSubtitle("Create JSON Login Object")]
    9. public class PoemsJSONLogin : Unit
    10. {
    11.     // See online manual
    12.     // https://docs.unity3d.com/Packages/com.unity.visualscripting@1.5/manual/vs-creating-visual-script-graph-unit.html
    13.  
    14.     // CONTROL PORTS //
    15.     [DoNotSerialize]
    16.     public ControlInput inputTrigger;
    17.     [DoNotSerialize]
    18.     public ControlOutput outputTrigger;
    19.  
    20.     // VALUE PORTS //
    21.     [DoNotSerialize]
    22.     public ValueInput command;
    23.  
    24.     [DoNotSerialize]
    25.     public ValueInput profile;
    26.  
    27.     [DoNotSerialize]
    28.     public ValueInput password;
    29.  
    30.     [DoNotSerialize]
    31.     public ValueOutput result;
    32.  
    33.     private string jsonResult;
    34.  
    35.     private class LoginDATA
    36.     {
    37.         public string command;
    38.         public string profile;
    39.         public string password;
    40.     }
    41.  
    42.     // Definition() defines what the node will be doing
    43.     protected override void Definition()
    44.     {
    45.         inputTrigger = ControlInput("inputTrigger", (flow) => {
    46.             LoginDATA jsonObject = new LoginDATA
    47.             {
    48.                 command = flow.GetValue<string>(command),
    49.                 profile = flow.GetValue<string>(profile),
    50.                 password = flow.GetValue<string>(password)
    51.             };
    52.  
    53.             jsonResult = JsonUtility.ToJson(jsonObject);
    54.  
    55.             return outputTrigger;
    56.         });
    57.  
    58.         outputTrigger = ControlOutput("outputTrigger");
    59.  
    60.         // Lable Names
    61.         command = ValueInput<string>("command", "LOGIN");
    62.         profile = ValueInput<string>("profile", "");
    63.         password = ValueInput<string>("password", "");
    64.         result = ValueOutput<string>("json", (flow) => jsonResult);
    65.  
    66.         // Adding Relations
    67.         Requirement(command, inputTrigger); // command must be set
    68.         Requirement(profile, inputTrigger); // profile must be set
    69.         Requirement(password, inputTrigger); // password must be set
    70.         Succession(inputTrigger, outputTrigger);
    71.         Assignment(inputTrigger, result);
    72.     }
    73. }
    74.  
    and the last bit to add the documentation that must be in an Edit folder

    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4. using Unity.VisualScripting;
    5.  
    6. [Descriptor(typeof(PoemsJSONLogin))]
    7. public class PoemsJSONLoginDescriptor : UnitDescriptor<PoemsJSONLogin>
    8. {
    9.     public PoemsJSONLoginDescriptor(PoemsJSONLogin unit) : base(unit) { }
    10.  
    11.     protected override void DefinedPort(IUnitPort port, UnitPortDescription description)
    12.     {
    13.         base.DefinedPort(port, description);
    14.  
    15.         switch (port.key)
    16.         {
    17.             case "inputTrigger":
    18.                 description.summary = "Trigger the creation of a JSON login string that will be sent to PHP server";
    19.                 break;
    20.             case "command":
    21.                 description.summary = "By default the PHP script will accept LOGIN as a valid command to login to the server";
    22.                 break;
    23.             case "profile":
    24.                 description.summary = "Valid profiles for now is DEV, PRF or OPOT";
    25.                 break;
    26.             case "password":
    27.                 description.summary = "Login password to gain access to the profile";
    28.                 break;
    29.             case "outputTrigger":
    30.                 description.summary = "Trigger the next action";
    31.                 break;
    32.             case "json":
    33.                 description.summary = "JSON Object string to be send to the next action in the flow graph";
    34.                 break;
    35.         }
    36.     }
    37. }
    38.  
    39.  
     
    ericb_unity likes this.
unityunity