Using VS under 2021.1.19f1 Following the instructions on another thread, I made my own custom class and Unity regenerated a few units to handle them but I noticed it didnt generate a Set New Chatline unit like it has for Vector2, here included to illustrate my point. This is my code. If I missed something, I'm listening. If I need to make a function to have the Set unit, how do I do that? Code (CSharp): using Unity.VisualScripting; using UnityEngine; [Inspectable] public class ChatLine { [Inspectable] public Sprite Pict; [Inspectable] public string Name; [Inspectable] public string Body; }
You can't really "Set" a class but you should be able to create a new instance of it via the "new" keyword for programmer naming and "Create" for human naming. UnityVS might default to human naming, I don't recall.
I trust it will surprise nobody that I had to look up whats a constructor. For whoever newbie stumbles on this someday, this is what a functioning custom class with a constructor looks like. Code (CSharp): using Unity.VisualScripting; using UnityEngine; [Inspectable] public class ChatLine { [Inspectable] public Sprite Pict; [Inspectable] public string Name; [Inspectable] public string Body; public ChatLine() { } public ChatLine(Sprite consPict, string consName, string consBody) { this.Pict = consPict; this.Name = consName; this.Body = consBody; } } The empty public CLASS() constructor is important. UnityVS will throw errors without it. Remember to regenerate your units. Someday Ill figure how to add default values to new classes, but not today.
You could solve that with a SuperUnit (also called SubGraph in newer UnityVS versions). Create a new Super Unit graph asset. You can search for "Super Unit" (or was it "Superunit"?) in the fuzzy finder. Created this way, it's embedded in the graph and non-reusable. But you can convert it to a graph asset from the Graph Inspector sidebar with the superunit selected. Or create a new graph asset the regular way and add Input and Output nodes manually. In the superunit create a new instance of the class and set it to a graph variable. Add all the individual Set nodes for the default values and wire them into the Super Unit's Input node. Use the newly created class instance as the target for Set nodes. For superunit input value ports, there's a bool. hasDefaultValue or something along those lines. You can access it in the Graph Inspector's sidebar with Input node selected, one of the last options for a value port. This will let you enter different input values per Super Unit's instance right on the Superunit node. Output the graph variable containing ChatLine instance to Output node's value port This gives you a reusable ChatLine instance creator node that can also set different default values per instance.