Hello,

I have a simple problem, but can't find the solution. I export a variable with export (int) var speed, but speed is null when I run the game. If I initialize the variable to zero, well I have an error division by zero. The variable appears in the Inspector, and I can change its value, but it seems to be completely ignored. Any ideas?

Thank you.

That's strange. Here's a few things I'd check:

-| Double check to make sure the exported variable is being set. -| If you are using a instanced scene, have you checked to see if the exported variable is not null in the base scene? It could be Godot is using the base scene's value over the instanced scene's value (which would be a bug, but...) -| Did you manually save the scene after setting the exported variable? Sometimes Godot does not realize the variable has changed and so you have to manually save using Control-S -| Are you setting Speed anywhere in your code? Perhaps you are setting it to null in the _ready function? (unlikely, but I've accidentally had this happen a few times :sweat_smile: )


I suppose you could always check to see if speed is null before using it, or use different code if speed is null. That would not really fix the issue, but I suppose it would 'fix' the issue temporarily.

Without seeing the scene and/or code, I think the problem is most likely either speed is being set to null somewhere in your code, or Godot is not saving the exported variable for some reason. The first is just a matter of looking through the code and seeing if anything looks amiss, while the second is probably Godot not saving the variable correctly, which should be fixable by manually saving (especially if you are using a instanced scene).

It's hard to say what the issue is for sure, so my apologizes if this is not terribly helpful! Hopefully this helps a little!

Thanks for your answer.

I am not sure what the problem was, but I fixed it by renaming the variable everywhere. Which makes me think, there is no refactoring option in Godot?

4 years later
a year later

Upping this thread since I just had the same problem and it turns out this is the consequence of having variables with the same names as custom classes. I had the custom class named "health" and a variable named "health". Because of this, the value of @export health was always null if set in the inspector (or 0 if I set it to int). Hope this helps someone.

21 days later

I also had a simpler problem but with a custom Resource , it worked at first then after changing the code it stopped working so I changed it back at with point the original code stopped working until I changed the variable. this kind of thing has happened twice for me now, I think the cod is cashing values when you build and it's not clearing correctly.
original name
@export var exit_target:Target
new name
@export var exit_target1:Target

6 months later

This was helpful, thanks for updating the post. I had a similar issue with a simple exported jumpForce value for my Rigidbody2D. Changing the name fixed the bug for me, so I guess Godot was the problem. I felt a little stupid there. No idea what I did wrong. Also, in case it's helpful to anyone in the future, I never got a null error. I was using the variable in a Vector2, so it just put 0 for me, and my player wouldn't jump.