Im posting this here for easy linking when the subject comes up on discord. Not meant to be thorough, just a quick brief, a condensed version of the class notes from a6, for inexperienced people who want to jump in head first.
You make Classes in your asset folder just like you make C# scripts. These classes are containers for graphs and variables.
You can set the scope of each class individually. You have the following options:
- Component: Your bread and butter. Add a BoltComponent to your game object, and drop one of these Component Classes on it to make things do stuff. Remember, Graphs and Variables are local instances on each GameObject.
- Scene: A scene singleton. Everything in a scene can access its contents.
- Singleton: An application singleton. Everything in your game can access this at all times.
- Asset: A Bolt ScriptableObject, a template used to generate assets. A Weapon Asset Class can be used to generate a Sword, Spear, and Hammer Bolt Asset.
There are four graph types in Bolt 2 that you will add to your class.
- Flow Behavior Graph: Where your classes will do most of their work. Events here (Start, Update, Etc) will function automatically without having a parent graph. These graphs are local only, although they can be activated and deactivated from other classes by making them "modular".
- Flow Function Graph: Similar to a C# function. Graph Variables on these graphs are not persistent, and will clear when the flow leaves, and thus are mostly used for single calculations. A Flow graph in one class can be used by another Class, but they are always executed on the Class they belong to. If your player has a TakeDamage function that modifies your Players Health, it's the Player class that will take the damage no matter what class uses the function. On Singletons, these graphs are effectively static, and don't need a reference. Functions can also be triggered in the editor for powerful editor scripts.
- Flow Macro Graph: Unlike functions, when you use one class's Macro in a different class's graph, they get inlined, the same as copying and pasting the graphs contents, so no need for references. Macro graphs also have the special ability of having multiple in flows and out flows, the ability to save their variables when flow leaves, and they can access events like Update. Great for reusable drag and drop modules!
- Flow State Behavior Graph: This beast is basically a series of Behavior graphs (States) chained together by Events that enable and disable them (Transitions). You use these to make State Machines. An AI might transition from "Look For Player" to "Chase Player" when it sees a player.
Each class can have a number of variables (which can be pretty much anything). Class variables will be accessible by every graph, while Graph Variables can only be accessed by the graph that owns them.
Class variables have a number of Access Modifiers, that...modify how they can be accessed.
- Get: Other classes can read the variable.
- Set: Other classes can change the variable.
- Inspect: The variable will be visible on the GameObject when you view it in the inspector.
- Override The variable's default value can be changed on the GameObject in the inspector.
Keep in mind Class Scope! Singleton variables can be accessed anywhere, but a Component is unique to each GameObject, and needs a reference to each instance you wish to access.
In Bolt "Events" are anything that can start flow through your graph. You should already understand how events like Update and Start work, so we're going to discuss Custom Events. These events live on your Class. Any Class can have a number of events, and each event can have a number of parameters. You can Listen to an event and you can Invoke an event (which triggers the Listeners)
Putting an Event on a Singleton Class makes them global, meaning that you can invoke it from anywhere, and all listeners in the game will hear it. Events on a Component Class, however, are unique to each GameObject you place them on. Remember, your game might have a million bad guys, so you have to specify which one receives the event.
By popular demand, heres a simple example:
This is a simple baddie. It has an Event called TakeDamageEvent, which you can see on the left next to the lightening bolt icon. It has a parameter called "DamageAmount". The BadGuy has a graph called HealthManager that has a Listener for the event. If something Invokes it, the BadGuy will log the damage. Note that we don't need any fancy references here, the Event is on the BadGuy, and by default it will listen to its Self.
Here is a simple class for a Sword. When it collides with something, we get the Collider, extract the GameObject (Bolt does this automatically, so you can just plug the Collider into anything you need) and we use the "Is" unit to check if our object is a BadGuy (Bolt will automatically find the component so just plug in that collider!). If the GameObject has a BadGuy Class, we Invoke! Note: The Collider is using Proxies to help organize the graph.
If you need to listen for a specific Event on a specific GameObject, you will also need a reference...unless the listener is already on the same GameObject to begin with, then bolt will handle it for you! In this case, this component is also on the game object with the BadGuy.
Customer support service by UserEcho