export variable is null

NekyiaNekyia Posts: 2Member


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.


  • TwistedTwiglegTwistedTwigleg Posts: 982Admin

    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!

  • NekyiaNekyia Posts: 2Member

    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?

Sign In or Register to comment.