Problem with @export var (godot bug ?)

Godot Version

4.2.2 stable

Question

Hello

I created a basic enemy who wait a random time between 2 values, then move in random direction, at fixed speed, and travels a random distance between 2 values.
For the waiting time and the distance, I use min and max variables with @export.

My problem is the distance value is always set to the default value, it never takes the values I set in the editor.

The enemy (slime) :
image

The enemy attached script :
image

It start in idle state :

When time is over, it switch to run state (actor is owner, so it’s slime node)

run state :

The values in the editor :
image

In the console I got this :

If I change speed in the parent, it also work fine like for the waiting time

I tried to change the variables names, to not set default, to move the variables into the parent, to let them and create new ones, to change type to float, to close and reopen slime scene and to restart godot, but nothing worked. If I change default values, it correcly takes the new default value, but never the values from the editor. So the enemy do what’s expected but if I want to change the distance I can’t do it from editor. Note I never had this issue with other exported var. For example the player I already made still work just fine.

If anyone can tell if I missed something or if it’s a bug (and in this case how to fix it)…

Thanks :slight_smile:

EDIT : I just added on my player an @export var for the damage of the main attack and have the same problem. When I hit the enemy it decreases it’s HP from the default value, not the value set in the editor. I tried to redifine the damage value in the code, it works. So all my @export var I’ve created before slime’s distance max / distance min still works when I change the value in the editor, but the new ones don’t.

What does the enter function of your State class look like? I’m wondering what code will be executed when you call super() from your run state. Anything in there that affects your exported variables?

EDIT: What does the scene where you have your enemies in look like?

Thank-you for your answer.

Nothing should affect the variables in enter function. It just define actor as owner if node isn’t attached to the state and emit a signal with new state :
image

and this is the scene I run, where the enemy is instancied :
image

I face similar issues constantly. For whatever issue, if your script is a tool script and you change export values on a scene it does not save on other scenes where it is added. I have to save it, then go to other scene where the changed scene exists and reload the export values in the editor.

1 Like

Thanks so much.
I guess it’s a conflict between the value on the scene itself and the one on the instancied one in an other scene. Both aren’t synchronized.

Problem solved, just need to know it

Exactly, that is what it is and it only happens with tool scripts.

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.