How to hide an exported variable from the inspector?

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By Zylann
:warning: Old Version Published before Godot 3 was released.

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?

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

volzhs | 2016-07-31 13:27

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

Zylann | 2016-07-31 14:23

:bust_in_silhouette: Reply From: vinod

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.

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.

Zylann | 2016-07-31 15:04

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.

vinod | 2016-07-31 15:16

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…

Zylann | 2016-07-31 15:21

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

vinod | 2016-07-31 15:23

:bust_in_silhouette: Reply From: Zylann

There is no keyword for that at the moment, so overriding _get_property_list() is the way to go.
Details: Ability to export a variable without showing it in the inspector · Issue #5988 · godotengine/godot · GitHub