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

Custom Units: adding variables to alter Value Input

Discussion in 'Visual Scripting' started by danthat, Oct 22, 2021.

  1. danthat

    danthat

    Joined:
    Aug 1, 2012
    Posts:
    25
    Is it possible to filter what shows in a CustomUnit's Definition() based on variables, like you can in the Inspector?

    For example:

    Code (CSharp):
    1. protected override void Definition()
    2. {
    3.             if (myBool)
    4.                 key = ValueInput<string>("Key", "Hello");
    5. }
    So toggling a 'myBool' checkbox in the CustomUnit would cause the key ValueInput to show/ hide? The above code is just an example, it obviously doesn't work, I need a checkbox to show on the Unit itself...

    Any advice much appreciated!
     
  2. MasterSubby

    MasterSubby

    Joined:
    Sep 5, 2012
    Posts:
    252
    [UnitHeaderInspectable] above a field or property to place it in the header, and [Inspectable] to show it in the graph inspector.

    Anytime an Inspectable is changed, the unit will be redefined. So your code is proper, and will work as intended.
     
  3. danthat

    danthat

    Joined:
    Aug 1, 2012
    Posts:
    25
    Perfect, exactly what I needed! Thank you!
     
  4. danthat

    danthat

    Joined:
    Aug 1, 2012
    Posts:
    25
    Sorry to be a pain and ask about this again, I'm expanding the same concept out a bit.

    Is there a way to show/ hide enums in the body of a Custom Unit based on what's been selected further up the hierarchy?

    So I have a series of enums and only show the appropriate ones based on what's been selected, and I can have a wide network of options on a single Custom Unit?


    Code (CSharp):
    1. public enum MainCategory
    2. {
    3. Beatles,
    4. StarWars,
    5. Nonsense
    6. }
    7.  
    8. public enum Beatles
    9. {
    10. John,
    11. Paul,
    12. Ringo,
    13. George
    14. }
    15.  
    16. public enum StarWars
    17. {
    18. Vader,
    19. Chewie
    20. }
    21.  
    22. public enum Nonsense
    23. {
    24. Urgle,
    25. Blartblart,
    26. Sausage
    27. }
    So selecting "StarWars" from the first enum would hide the Beatles and Nonsense options?

    Ideally this would be in the body of the unit, rather than in the graph inspector. They could be inspecatable in the header, but then I can't hide them based on what is/ isn't selected...
     
    Last edited: Nov 3, 2021