How to incorporate protected variables in Bolt?

Ozgur Duygu 4 years ago updated 4 years ago 6


I'm considerably new to Unity as a designer and I heavily rely on other scripts to make my games work. I'm currently developing a custom physics class and decided to do it entirely on Bolt. 

In other's scripts they use base classes and child classes and I couldn't find any information as to how inheritance works in Bolt compared to monoBehaviour. 

But my main question is how should I define protected variables e.g "protected vector2 velocity" in my graphs. Is there any downsides to set them as graph variables or what are the best practices to convert c# scripts to Bolt flow graphs. 

This is my first post on this community as a longtime lurker. Glad to be finally among you guys!

Thank you!

Bolt Version:
Unity Version:
Scripting Backend:
.NET Version (API Compatibility Level):
Satisfaction mark by Ozgur Duygu 4 years ago

Bolt does not utilize inheritance. Though that is on the roadmap under research, but only maybe someday going to happen, at this point in the product. Therefore, other than the types your importing, bolt itself has no knowledge of these concepts. 

It strictly uses Macros, which aren't actually functions or classes, just a graph with its own data behind the scenes to make it up. It contains no real start or end/return. When an event occurs, that is the start of a flow, but it still isn't the makeup of it. Therefore you can have a macro contain 50 events, or none. If none, you could have a flow to enter the macro, or use it just to return a value as an output, with no flow.

Now you can still directly translate a  C# script as bolt no problem. The events would kind of be your function, or Super Units (sorta static functions, only kind of) but there is no return other than the output ports you create our events you triggered with arguments, but you can use multiple events to act like inheritance . Though not recommended, that was really tricky to get right. Usually you'd just create a new super unit if it's not intended to be called like an event. 

There is no downside to using graph variables, those are more like private variables that only belong to the current graph. You can pretty much think everything but graph variables are public or static, even though there is many different styles of scope not directly in programming.

Probably went overboard, but I hope some of the information will help you understand what to do.


Thank you very much for your explanation! Now I understand more about how Bolt works. 

One more question. As I see on the roadmap there are plans to implement a Bolt to C# converter. Will there be any tools that do the opposite or is this going to be only a one way conversion? I always thought Bolt actually renders a c# script that emulates what's on the graph at the point of build, but possibly a crowded one.

Lastly, are there any examples to translate a c# script to bolt? If it was easier to translate Unity's own training sessions to Bolt that would gather much more people and hopefully make them adapt to Bolt more easily.  


I don't believe that is going to happen. But don't quote me on that. Bolt actually uses reflection to get all classes and it's variables/methods. From my perusing though the source, Bolt seems to use a mix of dictionaries and lists to hold unit and connection information and does other stuff to tell different parts when to run. I'm not too familiar on the deeper parts of the API though. So it's not actually a cs file, but kinda combines everything somewhere from information in other files in the project. Then runs it in real-time. This is why you can actively change your "code" in play mode. In scripting it needs to compile and rerun to see changes. Here, only the Bolt backend needs to compile once when imported. Your not creating new scripts, so no compiling necessary.

I don't have an example for you at the moment. Just find one line at a time. See if in the search you can find the unit that would represent each individual part, section, or word of that line. If not, chances are type or assembly wasn't added. Search through that then add them. After you do it a couple times, the ideas of how the basics work will be easier. It'll be more of, how can I actively use these specific units in different ways.

If you haven't gotten it in the next few hours, I'll be around to actually be on a computer and show you something.

Thanks a lot for the thorough explanation!


Jason's explanation is 100% correct. To confirm, there are no plans to ever have Bolt convert from C# to graphs (because the graphs are just a subset of C#, this is not technically possible for all cases).

Okay this is sad on my part but I completely understand.