Search Unity

NullMeansSelf Attribute

Discussion in 'Visual Scripting' started by bearcoree, Oct 31, 2021.

  1. bearcoree

    bearcoree

    Joined:
    Mar 8, 2016
    Posts:
    72
    Heya,

    according to this thread, the easiest way to wait for a coroutine in Bolt / Visual Scripting is a custom Unit. This itself works fine, however, I'd like for a variable I'm passing into the custom Unit to be pre-filled, just like the default behaviour.



    Here's the code from the custom Unit in the screenshot:
    Code (CSharp):
    1. public class TestNullMeansSelfNode : Unit
    2. {
    3.     [NullMeansSelf]
    4.     public ValueInput InteractableInput;
    5.  
    6.     protected override void Definition()
    7.     {
    8.         InteractableInput = ValueInput<GameObject>("NullMeansSelfTest", null);
    9.     }
    10. }
    I'm trying to use the NullMeansSelf Attribute to get this behaviour in my custom Unit, but it seems to either not work outside of the Bolt Assembly or there is additional setup required that I don't know about. Is there any documentation about this Attribute? I could not find any.

    I found the Attribute when Looking at the Definition of the "On Collision Enter" Node that comes with Bolt and it seems to use this Attribute:



    How do I get an Input Pre-Filled in custom Units?
    Any help would be lovely! ❤️
     
  2. inferno222

    inferno222

    Joined:
    Apr 29, 2014
    Posts:
    6
  3. termway

    termway

    Joined:
    Jul 5, 2012
    Posts:
    80
    The key in the
    ValueInput<T>(string key, T default)
    method must be the same as the
    ValueInput
    variable name, else it won't work (you will have
    None⦾
    instead of
    This⦾
    )
    You might also want to add the
    .NullMeansSelf()
    method in your
    Definition()
    method (almost all the VisualScripting base unit use it with the NullMeansSelf attribute).

    Code (CSharp):
    1. public class TestUnit : Unit
    2.     {
    3.         [DoNotSerialize]
    4.         [NullMeansSelf]
    5.         public ValueInput TestBoth { get; protected set; }
    6.  
    7.         [DoNotSerialize]
    8.         [NullMeansSelf]
    9.         public ValueInput TestAttributeOnly { get; protected set; }
    10.  
    11.         [DoNotSerialize]
    12.         public ValueInput TestWithoutAttribute { get; protected set; }
    13.  
    14.         [DoNotSerialize]
    15.         [NullMeansSelf]
    16.         public ValueInput TestBug { get; protected set; }
    17.  
    18.         protected override void Definition()
    19.         {
    20.             TestBoth = ValueInput<Transform>(nameof(TestBoth), null).NullMeansSelf(); // Works
    21.             TestAttributeOnly = ValueInput<Transform>(nameof(TestAttributeOnly), null); // Works
    22.             TestWithoutAttribute = ValueInput<Transform>(nameof(TestWithoutAttribute), null).NullMeansSelf(); // Does not work
    23.             TestBug = ValueInput<Transform>("TestBugErr", null).NullMeansSelf(); // Does not work
    24.         }
    25.     }
    26.  
    upload_2023-5-26_18-25-57.png
     
    Last edited: May 26, 2023
    CaramelMou and PanthenEye like this.