Structs - RealityStop/Bolt.Addons.Community GitHub Wiki

StructAsset

The StructAsset lets you visually design C# structs inside Unity using Visual Scripting.
Structs are lightweight value types ideal for small data containers or configurations.


Features

  • Create value types (struct) with public or private members.
  • Define fields, properties, constructors, and methods visually.
  • Add interfaces and custom attributes.
  • Supports [Serializable], [Inspectable], [IncludeInSettings], and IDefinedEvent.
  • Integrates with FlowGraphs to generate logic for methods, getters, setters, and constructors.
image

Getting Started

1. Create a StructAsset

In the Project window:
Create → Visual Scripting → Community → Code → Struct


2. Struct Info

Setting Description
Title The name of the struct (e.g., Vector2D).
Category The namespace where the struct will be placed (e.g., Game.Math).
Attributes Struct-level attributes like [Serializable] or [IncludeInSettings(true)].
image

3. Options

Option Description
Serialized Adds [Serializable].
Inspectable Adds [Inspectable].
Include In Settings Adds [IncludeInSettings(true)].
Flag for Defined Event Filtering Implements IDefinedEvent for Defined Event filtering.
Interfaces Interfaces that the struct implements (e.g., IEquatable<T>).

4. Define Members

Constructors

Option Description
Scope Access modifier (e.g., public).
Initializer Type None or This (structs cannot call base()).
Parameters Define constructor parameters.
Body Graph Optional FlowGraph for constructor logic.
image image

Example result:

public Vector2D(float x, float y)
{
    X = x;
    Y = y;
}

Fields

Add variables directly to the struct.
Each field can have:

Option Description
Scope Access modifier (e.g., public, private).
Modifier Optional modifier like static.
Name The field or property name.
Type The data type.
Default Value Optional default initializer.
Attributes Optional field or property attributes.
image

Example result:

public float X;
public float Y;

Properties

Properties can include getter and setter FlowGraphs, letting you define custom logic visually.

Options include:

Option Description
Getter / Setter FlowGraphs Optional logic for custom get/set.
Getter Scope Access level for the getter.
Setter Scope Access level for the setter.
image image

Example result:

public float Magnitude
{
    get
    {
        return UnityEngine.Mathf.Sqrt(((X * X) + (Y * Y)));
    }
}

Methods

Add custom struct methods with parameters, return types, and logic graphs.

Option Description
Scope Access modifier.
Modifier Optional method modifier.
Name The method name.
Return Type The return type (e.g., void, int).
Parameters The list of input parameters.
Body Graph The FlowGraph used for logic.
Attributes Optional method attributes.

Method

Method Graph

Example result:

public void Normalize()
{
    float length = Magnitude;
    X = (X / length);
    Y = (Y / length);
}

Required Info

  • Implement any info that the struct requires
image

Graph:

image

Example result:

public bool Equals(Vector2D other)
{
    return (X == other.X && Y == other.Y);
}

5. Compile

Compile your struct using C# Preview or Addons → Compile Selected. This generates a valid .cs file that behaves like a standard Unity struct.

Final Result

#pragma warning disable
using System;
using Unity.VisualScripting;


namespace Game.Math
{
    [Serializable]
    [IncludeInSettings(true)]
    public struct Vector2D : IEquatable<Vector2D>
    {
        public float X;
        public float Y;

        public float Magnitude
        {
            get
            {
                return UnityEngine.Mathf.Sqrt(((X * X) + (Y * Y)));
            }
        }

        public Vector2D(float x, float y)
        {
            X = x;
            Y = y;
        }

        public void Normalize()
        {
            float length = Magnitude;
            X = (X / length);
            Y = (Y / length);
        }

        public bool Equals(Vector2D other)
        {
            
            return (X == other.X && Y == other.Y);
        }
    }
}

Member Units

A new CSharp section appears in the fuzzy finder, giving you units for:

  • Asset-defined members (methods, properties, fields)
  • The asset type (typeof(CurrentAssetType))

See Also

⚠️ **GitHub.com Fallback** ⚠️