+1 vote

This might sound silly, but I need to save a script variable in the scene, so I use the export keyword. But at the same time, it is showing in the editor. I don't want it to be visible because it is cryptic to the user, and it cannot be edited this way (a plugin does that instead). Is there a way to hide this variable but still have it serialized?

in Engine by (28,835 points)

did you mean you don't want to see exported variable to someone who uses your plugin with godot editor?

Yes, the Unity equivalent would be [HideInInspector][SerializeField].

2 Answers

+2 votes
Best answer

There is no keyword for that at the moment, so overriding _get_property_list() is the way to go.
Details: https://github.com/godotengine/godot/issues/5988

by (28,835 points)
+1 vote

I think the export variable doesn't do anything other than just showing it in the inspector.
All the variables in gdscript are public. Correct me if this is something different.

by (750 points)

No, actually export does two things:
- It is shown in the inspector
- It is saved in the scene
I just want the variable to NOT show in the inspector, because it is not meant to be edited this way. But at the same time, I want it to be serialized when the scene is saved.

Oh, yeah now I remember, exported vars are saved in the scene.

So, re-initialising the variable inside _ready will work? So whatever the value set in inspector, it will be changed when the game starts.

I don't want to do anything in _ready(), reinitializing is pointless. I just want the variable to not show in the inspector when someone edits the scene. But if I remove export the variable won't be saved, I want it to be saved in the scene.

The problem is, this variable is edited with an editor plugin instead, so there is no point in showing its raw value in the inspector...

So this will require a change in the source code. May be introduce a serialize keyword or something like that

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read Frequently asked questions and How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to webmaster@godotengine.org with your username.