Search Unity

Resolved What are the conditions for "Unit is never entered"?

Discussion in 'Visual Scripting' started by kyubuns, Feb 26, 2021.

  1. kyubuns

    kyubuns

    Joined:
    Aug 6, 2013
    Posts:
    138
    I wrote my own script that I will write about later.
    The node itself is working as expected, but the connected node is in a state of "Unit is never entered".
    Why is this?

    Env
    - Unity2021.1.0b8
    - VisualScripting 1.5.1-pre.3

    109340218-1495c600-78ac-11eb-8092-38a64684fca9.png 109340177-05af1380-78ac-11eb-8151-1c27850bdd61.png

    Code (CSharp):
    1. using System.Collections;
    2. using Unity.VisualScripting;
    3. using UnityEngine;
    4.  
    5. namespace ApureEasing
    6. {
    7.     [UnitTitle("FloatEasing")]
    8.     [UnitCategory("ApureEasing")]
    9.     public class FloatEasingNode : Unit
    10.     {
    11.         [DoNotSerialize]
    12.         public ControlInput start { get; private set; }
    13.  
    14.         [DoNotSerialize]
    15.         public ControlOutput tick { get; private set; }
    16.  
    17.         [DoNotSerialize]
    18.         public ValueOutput value { get; private set; }
    19.  
    20.         [DoNotSerialize]
    21.         public ControlOutput complete { get; private set; }
    22.  
    23.         [DoNotSerialize]
    24.         public ValueInput easing { get; private set; }
    25.  
    26.         [DoNotSerialize]
    27.         public ValueInput duration { get; private set; }
    28.  
    29.         [DoNotSerialize]
    30.         public ValueInput endValue { get; private set; }
    31.  
    32.         [DoNotSerialize]
    33.         public ValueInput startValue { get; private set; }
    34.  
    35.         private float startTime;
    36.  
    37.         protected override void Definition()
    38.         {
    39.             start = ControlInputCoroutine(nameof(start), RunCoroutine);
    40.             tick = ControlOutput(nameof(tick));
    41.             complete = ControlOutput(nameof(complete));
    42.             easing = ValueInput(nameof(easing), Easing.Linear);
    43.             duration = ValueInput(nameof(duration), 1f);
    44.             startValue = ValueInput(nameof(startValue), 0f);
    45.             endValue = ValueInput(nameof(endValue), 1f);
    46.             value = ValueOutput(nameof(value), GetOutput);
    47.         }
    48.  
    49.         private IEnumerator RunCoroutine(Flow flow)
    50.         {
    51.             var d = flow.GetValue<float>(duration);
    52.             startTime = Time.time;
    53.  
    54.             while (startTime + d > Time.time)
    55.             {
    56.                 yield return tick;
    57.                 yield return null;
    58.             }
    59.             yield return tick;
    60.            flow.Run(complete);
    61.         }
    62.  
    63.         private float GetOutput(Flow flow)
    64.         {
    65.             var t = flow.GetValue<Easing>(easing);
    66.             var s = flow.GetValue<float>(startValue);
    67.             var e = flow.GetValue<float>(endValue);
    68.             var d = flow.GetValue<float>(duration);
    69.  
    70.             if (!(startTime + d > Time.time)) return e;
    71.             var v = (Time.time - startTime) / d;
    72.             return Mathf.Lerp(s, e, EasingConvert.Get(t, v));
    73.         }
    74.     }
    75. }
     
    Haneferd likes this.
  2. karolwieczorek9

    karolwieczorek9

    Joined:
    Jun 8, 2015
    Posts:
    6
    Just had same problem. You need to call "Succession(enter, exit)" method
    At the end of Definition method just write:
    Succession(start, tick);
    Succession(start, complete);
     
  3. kyubuns

    kyubuns

    Joined:
    Aug 6, 2013
    Posts:
    138
    Fixed!!!!! Thank you!!!
     
  4. ChaosCraft

    ChaosCraft

    Joined:
    Feb 8, 2022
    Posts:
    8
    Where did you find this out?
    I'm trying to do more complex things with my nodes, but advanced usage info seems hard to find (for example, how does flow actually work)
     
  5. ncr100

    ncr100

    Joined:
    Jul 23, 2015
    Posts:
    32
    kyubuns and ChaosCraft like this.
  6. karolwieczorek9

    karolwieczorek9

    Joined:
    Jun 8, 2015
    Posts:
    6
    I'm not good with documentation (plain stuff out of context) so I just learn by jumping from one open github to another, reading code. Also looking for some Youtube tutorials, some of them have links with sources where is also good place to read some code.