Search Unity

Resolved Is there any way to register Type Options and Node Library from script?

Discussion in 'Visual Scripting' started by SolarianZ, Aug 17, 2022.

  1. SolarianZ

    SolarianZ

    Joined:
    Jun 13, 2017
    Posts:
    237
    Is there any way to register Type Options and Node Library from script?

    upload_2022-8-17_10-29-26.png
     
  2. PanthenEye

    PanthenEye

    Joined:
    Oct 14, 2013
    Posts:
    2,075
    Decorate your classes with [IncludeInSettings(true)] attribute. You still have to regen nodes manually, though. There was API for that as well, something along the lines of UnitOptions.Update() or some such.
     
    REDACT3D_ and ironwolf like this.
  3. ironwolf

    ironwolf

    Joined:
    Oct 26, 2010
    Posts:
    9
    @PanthenEye Thank you very much for this information. I was looking for an option to exclude some classes from Node Generation and it seems that [IncludeInSettings(false)] do the trick :)

    I wonder if there is an option to exclude whole namespace?

    And is there some place where all these attributes are documented?
    I can find them manually in script refs: https://docs.unity3d.com/Packages/com.unity.visualscripting@1.7/api/Unity.VisualScripting.html
    but I have to guess what each of them possibly do and how to use it :(
     
  4. PanthenEye

    PanthenEye

    Joined:
    Oct 14, 2013
    Posts:
    2,075
    I don't believe so. It was supported in Bolt 2 which has since been discontinued.

    I'm also not aware of any Unity docs covering these more esoteric attributes. My knowledge comes from being and ex-Bolt 1 user from the early days before Unity acquired it and rebranded it to UVS.

    They're currently working on a new major version of Unity visual scripting. The whole workflow might change once that drops in a year or two. It's not confirmed but I believe it's likely to be a major if not full rewrite.
     
    REDACT3D_ likes this.
  5. Trindenberg

    Trindenberg

    Joined:
    Dec 3, 2017
    Posts:
    398
    I do wonder if there's a way to strip/trim the massive node database of unused items, and whether that would speed things up/lessen memory hog. Just the basic setup from start is 20k database items, which assume go into memory for lookup at runtime. Is a dictionary much quicker to find 1 of 200 items than 1 in 20000 items?

    And yes you can access/update/remove from Type/Node options via script but I'm rusty at this point on it.
     
  6. REDACT3D_

    REDACT3D_

    Joined:
    Nov 8, 2020
    Posts:
    222

    When an update drops after you complete the certification

    R.gif


    still.. excited to see some improvements
     
  7. PanthenEye

    PanthenEye

    Joined:
    Oct 14, 2013
    Posts:
    2,075
    The new version will have the high-performance interpreted runtime which means a new custom node API. And it'll migrate from current IMGUI UI solution to Graph Tools Foundation graph framework they're cooking up so UI/UX will also completely change technologies and ways of scripting it. And since they're making these major changes, it's likely they will migrate from FullSerializer to Unity's native one which is a lot more limited so it's unclear what'll happen with graph format, etc. If it won't be directly backwards compatible, it should at least have a migration tool for native nodes and reflected nodes. Custom nodes are unlikely to survive the transition.

    It's also unclear if they'll go beyond that as far as the overall framework and its API is concerned, they stopped communicating with the community a couple months ago so it's a toss up. Time will tell but timelines are also unclear, this new major version depends on Graph Tools Foundation being present and they're in the process of integrating it within the core of the engine and 2023.1 alpha doesn't have it yet so it might not come until Unity 2024.1 or later.

    Long story short, current UVS isn't going away anytime soon, it's likely to remain as is for the next two years at least. But it's just my speculation.
     
    Yuchen_Chang and REDACT3D_ like this.
  8. SolarianZ

    SolarianZ

    Joined:
    Jun 13, 2017
    Posts:
    237
    You can access Type Options through property `BoltCore.Configuration.typeOptions` and access Node Library through property `BoltCore.Configuration.assemblyOptions`. After modifying the properties, you should call `PluginConfigurationItemMetadata.Save()`, `Codebase.UpdateSettings()` and `UnitBase.Rebuild()`.

    Sample Codes (Tested on Unity 2021.3.0):
    Code (CSharp):
    1. [MenuItem("Window/Bamboo/Visual Playable/Setup Playable Nodes")]
    2. public static void Setup()
    3. {
    4.     var boltTypeOptionsChanged = false;
    5.     var coreConfig = BoltCore.Configuration;
    6.     foreach (var type in CollectPlayableTypes())
    7.     {
    8.         if (!coreConfig.typeOptions.Contains(type))
    9.         {
    10.             coreConfig.typeOptions.Add(type);
    11.             Debug.Log($"Add {type.FullName} to Visual Scripting type options.");
    12.             boltTypeOptionsChanged = true;
    13.         }
    14.     }
    15.  
    16.     if (boltTypeOptionsChanged)
    17.     {
    18.         var typeOptionsMetadata = coreConfig.GetMetadata(nameof(coreConfig.typeOptions));
    19.         typeOptionsMetadata.Save();
    20.         Codebase.UpdateSettings();
    21.         UnitBase.Rebuild();
    22.     }
    23.  
    24.     // coreConfig.assemblyOptions.Add(xxx);
    25.     // var assemblyOptionsMetadata = coreConfig.GetMetadata(nameof(coreConfig.assemblyOptions));
    26.     // assemblyOptionsMetadata.Save();
    27.     // Codebase.UpdateSettings();
    28. }
     
    PanthenEye likes this.
  9. bubicus

    bubicus

    Joined:
    Apr 18, 2013
    Posts:
    8
    @SolarianZ Is UnitBase only accessible through the older Bolt package and not through the official Unity Visual Scripting package?

    I have UVS 1.7.8 installed through the package manager. It appears to be the latest official version available, but it doesn't seem to show UnitBase within the Unity.VisualScripting namespace (despite the documentation saying it's there and that it's public and static.)

    upload_2023-1-28_14-45-45.png
     
  10. SolarianZ

    SolarianZ

    Joined:
    Jun 13, 2017
    Posts:
    237
    No, its still public. You can check it here: https://docs.unity3d.com/Packages/c...ase.html#:~:text=public static class UnitBase
     
  11. bubicus

    bubicus

    Joined:
    Apr 18, 2013
    Posts:
    8
    Yes, that is the documentation I was referring to... however, I still don't see it in the namespace when I am coding in Visual Studio.

    After further research, I discovered that it would work if I created a completely clean, new project. Therefore, there is a different issue related to how Unity is importing the packages, but I guess that's a different problem for me to solve...

    Edit for anybody curious: it ends up that because I was using UnitBase.Build() in an editor script, I needed to add VisualScripting.Flow.Editor to my assembly definition for my editor scripts. That fixed the problem!
     
    Last edited: Jan 30, 2023