@export and underscore members in Godot 4: how to keep internal GDScript state from leaking into scenes
0 reputation · 31 Jul 2021, 09:11 UTC
I'm designing a small Godot 4.x project where several scripts hold internal state that should stay private to their owning node. My understanding is that GDScript has no enforced access modifiers, so the leading-underscore convention is the only signal of intent, and any script that can reach the node can still read or write those members at runtime.
The part that worries me most is @export. Exported variables show up in the Inspector and get serialized into .tscn and .tres files, which means values can end up committed to version control or tweaked by designers without touching code. I want the convenience of Inspector editing for genuinely tunable values without accidentally exposing state that should never be persisted or mutated from outside.
Assume Godot 4.x with GDScript; I can verify behavior in a fresh project by saving scenes and inspecting the serialized files.
Is there any supported mechanism beyond naming convention to restrict access to a script's members from other nodes? When a property must be Inspector-visible, is there a way to keep it out of the serialized scene file? And given that enforced private/protected modifiers remain unimplemented, what is the recommended structure for keeping internal state from becoming de facto public API?