How to access variables of a static class with visual scripting

I have a static class called Game that has a variable playerID. I need to access this using visual scripting. I see that custom monobehavior components show up in the visual scripting System namespace but I don’t see where static classes show up. Any advice?

Thank you.

I’ve spent a day trying to access a static class from visual scripting without any luck. Looking through the documentation I see a way to set visual scripting variables from a C# script. According to the documentation I need to declare:

using Ludiq;
using Bolt;

and then use:

Variables.Application.Set("score", 100);

When I do this I’m told the type or namespace Bolt and Ludiq can not be found.

I’m confused why I would need these. Isn’t Visual Scripting a separate package to Bolt?

I’m using Visual Scripting 1.6 and looking at documentation for 1.6.

If it’s not a monobehaviour, you need to decorate the class with this attribute to add it to visual scripting

using Unity.VisualScripting;

[IncludeInSettings(true)]
public class MyClass
{
...

Then you can get visual scripting to look up any new scripts you have added and update its library:

File → Project Settings → Visual Scripting
Click the “Regenerate Units” button in the settings panel

1 Like

That can’t be the docs for 1.6 if it says to use Ludiq and Bolt namespaces since those have been entirely migrated to Unity.VisualScripting but Hikiko66’s advice is applicable with the IncludeInSettings attribute.

EDIT: Looks like 1.6 docs still have outdated info in relation to Ludiq and Bolt namespaces. All content under those namespaces is now in Unity.VisualScripting.

1 Like

Thanks for the suggestions. Adding the decorator made the static class show up in the Codebase.

[IncludeInSettings(true)]
public static class Game

{
    public static bool ready = false;
}

However I don’t see a way to get the value of the static class.

I can create a Unit to set it through Application > Codebase > Game > Set Ready.

There is no option to create a unit for Get Ready.

The ready bool should be freely accessible in fuzzy finder under your class with both Set and Get node variants. If you added the bool after you regenerated units you need to regenerate units again for any changes in scripts to show up. There’s an automatic unit update option available in UnityVS preferences that will automatically detect edits to already added types after compilation. It’s much faster than full regen but it can be glitchy.

After I regenerated I can see a Get Ready. Thank you!

I have a custom class as a member of the static class ‘Game’ called ‘PlayerData’. I have a unit generating for "Game Get PlayerData’ and I can set it to a local graph variable.

How do I access a member of that custom class, in this case playerName once it is saved as a graph variable?

[IncludeInSettings(true)]
public class PlayerData
{
    public Guid id = Guid.NewGuid();
    public string playerName = "";
    public int hitpointMax = 100;
    public int hitpointCurrent = 100;
    public int vitalityMax = 100;
    public int vitalityCurrent = 100;
}

If memory serves me correctly, you might want to decorate the class and each of the variables you want to access with [Inspectable] attribute for data to display in UVS’ Variables window. And unit regen should produce all the Get, Set nodes for all public members. So you Get “playerName” for example using the graph variable holding PlayerData as an input for target.

This works great. Thank you.

I’m having similar difficulties understanding how to invoke actions with visual scripting. Any advice would be much appreciated.