Not a Bug

Object variable type set to null when exiting play mode

Keenan Woodall 3 years ago updated 3 years ago 6

I'm still new to Bolt so I may be doing something wrong, but I created a variable called "rb" and set its type to Rigidbody. When I press play it works fine but when I stop playing the type goes to "Null"

Bolt Version:
Unity Version:
Scripting Backend:
.NET Version (API Compatibility Level):

The dev got back to me ridiculously quickly and answered my question thoroughly.

Satisfaction mark by Keenan Woodall 3 years ago
Not a Bug

Hi Keenan,

That's normal and shouldn't be a problem. Let me explain:

Variables are not strongly typed. That means each of them is stored as only an "object". When you set the type to Rigidbody  but don't give it a reference, under the hood, this variable only has a "null" value of no particular type. The Bolt inspector will remember that you chose Rigidbody for a little while to allow you to assign a reference, but if you close it, it'll revert back to null. 

None of that explanation is important for you to understand really, because a "null rigidbody" is just the same thing as a "null anything else". 

Let me know if that answers your question!

So the type I assign it doesn't matter? Its type is determined after I assign an object to it?

Yep! And it can change during runtime if you assign another object to it.

The type field is just there to choose which inspector to display.

Holy crap! I don't know how I missed the part where this isn't generating c# code. May I ask what it IS doing? This just got even more impressive, haha.


Haha! Well how did you think live editing was working? Or why there was no compile time? ;)

Basically, Bolt runs everything from memory. It's using delegates and JIT emitted MSIL to run closer to script speed, but keeps the flexibility of having everything editable at runtime.

In Bolt 2, code will be generated optionally. This will give you top performance on some or all graphs, while maintaining editability and debugging on others.

Yea I was a little confused when I was able to change the flow graph at runtime haha. Great work man! As soon as I think I'm good at programming I get humbled! :)