Godot Version
v4.5.1.stable.steam [f62fdbde1]
Question
I tried searching for this in the docs and couldn’t find it, so I asked chatgpt after, and its method didn’t work. so this is the last place I could think of to figure this out. Also, just saying, I’m using GDScript for this.
I’m having trouble figuring out how to make an @export_group that has a boolean on the group itself that decides whether we can open it in the inspector or not. For example, if you check a Camera2D nodes inspector, you’ll see that there’s three groups called Position Smoothing, Rotation Smoothing and Limit, which can only be opened if the boolean on the group itself is set to true.
This is what I mean VVV
Does anyone know how I can replicate this?
For reference, this is what chatgpt told me to do, and it didn’t work at all:
@export_group("Test")
@export var test_enabled := false
@export_group("Test", "test_")
@export var test_number := 64.0
This forum should be on your list above ChatGPT because it will confidently make up a solution that doesn’t exist.
As far as I know, you cannot yet in GDScript. This was a new feature added into the editor in 4.5, and to my knowledge it hasn’t yet been exposed to GDScript.
So far this is the closest you can probably get just using @export annotations:
@export_category("Movement")
@export var movement_enabled: bool = false
@export var speed: float = 300.0
If you really want this functionality, you might be able to get it by playing with _get_property_list(). Which, if I had more time, I might be interested in playing with it myself. I got to that from GDScript exported properties — Godot Engine (latest) documentation in English
Otherwise you may need to do it in C++.
I generally ignore “I tried ChatGPT but…” questions, but today is your lucky day.
@export_group("Foo")
@export_custom(PROPERTY_HINT_GROUP_ENABLE, "") var foo_enable := false
@export var bar := 0
It’s doable by implementing _validate_property() or _get_property_list() as well.
3 Likes
Oh, alright. I’ll try looking into that and see if I find anything, ty
I just tried this out, and it actually worked! Ty man, I’ll make sure to not use chatgpt again lol
3 Likes
If you want to use @normalized’s suggestion (thanks BTW - I learned something new) and you want to reset those values in the group, you need to make a tool script and create a setter for the custom export. For the @tool script to work, you’ll also have to restart your project in the editor. (Project → Restart Project)
This worked for me, and if I changed the Speed value to 525 and then turned the Movement group off, the value was set back to 300. Because I assume that’s what you’re going for here.
@tool
class_name Player extends CharacterBody2D
const DEFAULT_SPEED = 300.0
#Movement export variables
@export_group("Movement")
@export_custom(PROPERTY_HINT_GROUP_ENABLE, "") var movement_enabled: bool = false:
set(value):
movement_enabled = value
if value == false:
speed = DEFAULT_SPEED
@export var speed: float = DEFAULT_SPEED
2 Likes