tutorials/scripting/gdscript/gdscript_exports #143
Replies: 16 comments 12 replies
-
What about |
Beta Was this translation helpful? Give feedback.
-
There's no mention that a description text can be added to exported vars starting the preceding line with ##. ## This is my description text
@export var a: int |
Beta Was this translation helpful? Give feedback.
-
What if you want to listen to a value being changed for exported properties, for instance a bool value changing from true to false. And preferably outside of |
Beta Was this translation helpful? Give feedback.
-
What about if you only want to specify a min or a max to a value instead of a range? For example, if I am exporting a variable called max_health, I want to set the min to 1 (as 0 for max health makes no sense), but I don't want to provide an upper limit. How would I do that? It seems like an @export_min and @export_max might be nice or a keyword you can use in the @export_range (note that INF won't work for ints I believe). |
Beta Was this translation helpful? Give feedback.
-
Hello people, I get some script from 2022 version of Godot. There is a code write in this format: '''export (int, 0, 256) var max_polyphony:int = 96 setget set_max_polyphony''' Can you help me to parse it to actual 4.3 GDScript? Thanks. |
Beta Was this translation helpful? Give feedback.
-
How do I export min-max-values like the ones in the particle system? |
Beta Was this translation helpful? Give feedback.
-
I had the Problem that when I changed an exported property from a tool script the scene was not marked as "modified". The solution was to use undo_redo. Maybe this can be mentioned here |
Beta Was this translation helpful? Give feedback.
-
@export requires a type so Variant can't be exported. Here is a partial, simple work-around. class_name ExportableVariant
extends Resource
enum Type {
BOOL = TYPE_BOOL,
INT = TYPE_INT,
FLOAT = TYPE_FLOAT,
VECTOR2 = TYPE_VECTOR2,
VECTOR3 = TYPE_VECTOR3,
}
@export var type: Type = Type.BOOL
@export var value_bool: bool = false
@export var value_int: int = 0
@export var value_float: float = 0.0
@export var value_vector_2 := Vector2()
@export var value_vector_3 := Vector3()
static func from_float(value: float) -> ExportableVariant:
var result := ExportableVariant.new()
result.type = Type.FLOAT
result.value_float = value
return result
func get_value():
match type:
Type.BOOL:
return value_bool
Type.INT:
return value_int
Type.FLOAT:
return value_float
Type.VECTOR2:
return value_vector_2
Type.VECTOR3:
return value_vector_3 This can be useful when you want to tweak easily tweak animations between instances with property tweeners. For example, an openable container class (some containers you might want to use a hinge joint, others you might want to change color). extends Openable
@export_group("Required Nodes")
@export var hinge: Node3D = null
@export_group("Animation Properties", "animation")
@export var animation_property_path: String = "rotation:x"
@export var animation_final_value := ExportableVariant.from_float(-150)
@export var animation_time: float = 2.5
@export var animation_ease_type: Tween.EaseType = Tween.EaseType.EASE_IN
@export var animation_transition_type: Tween.TransitionType = Tween.TransitionType.TRANS_CIRC
func _open() -> void:
_is_tweening = true
var tween: Tween = create_tween()
tween.tween_property(hinge, animation_property_path, deg_to_rad(animation_final_value.get_value()), animation_time).set_ease(animation_ease_type).set_trans(animation_transition_type) |
Beta Was this translation helpful? Give feedback.
-
Regarding |
Beta Was this translation helpful? Give feedback.
-
1.Will there ever be anything to read further? Every time I come here and read to the bottom where it says "before reading further" and kinda wish there was something else to read on like you'd expect lol. While I'm sure one could just figure out advanced exports on their own, I figure documentation is what this is for, right? Or if there's really nothing to cover that can be thought of, why is there an advanced section at all? At that point maybe rewriting that section would help to reduce confusion, as when I first came to this page early on, I know I tried looking for the advanced knowledge for 10-15 minutes before I realised it was never added to the page lol (I'm stupid and prob have memory loss bc that's happened multiple times, even later on LMAO) It's been so long, I'm surprised it's still like that. I guess I half expected someone to point it out for me, but I don't think that's happening lol. I don't know why, it bugs me a lot 2.Also, an aside (and the reason I came here and found out), there really should be a way to add more prefixes to Maybe there's a built-in way to do this already, but it was not made clear in the one section talking about I suggest either allow alternative prefixes (and keep the first one as the group name) or simply ignore underscores at the start of variable names for this scenario. Also keep in mind with that decision, though, not everyone abides by or wants to abide by GDScript's official standards: Some people might use 3.This is not a request, this is a cry for help. And it's in no way related to exports. PLEASE ADD ACCESS MODIFIERS AND OVERLOADING TO GDSCRIPT. OH MY GOD I HATE NOT HAVING THEM. THE ONLY REASON I USE GDSCRIPT IS FOR PERFORMANCE AND BREVITY. I DISLIKE SO MUCH ABOUT GDSCRIPT, BUT IT'S WITHOUT A DOUBT THE GENERALLY BEST OPTION. AND WHY IS THE EDITOR SO MID TO MAKE ME USE VSCODE'S SLIGHTLY BETTER ALTERNATIVE? AND WHY DOES EVERYTHING ERROR AND REQUIRE A RELOAD EVERY TWO SECONDS? MY BELOVED C# WAS SACRIFICED FOR THE GDSCRIPT TEAM'S SINS!!! thank you. and buff c# pls i know where you live btw ;) jk, but i will find out soon if this is not added >:( Anyway yeah, thanks for reading lol For legal reasons, I was joking about finding where you live...? Anyway, back to coding! I hope this comment wasn't for nothing, but I doubt my GDScript requests will be done seeing how nothing has progressed in that direction in the whole of its existence lol. I use this engine for free, though, so I have no room to complain, just a genuine urge to lmao. Although complaints are good to know for software of any kind...so I spread the word anywhere I can lol |
Beta Was this translation helpful? Give feedback.
-
Exported floating point values default their precision to 3 decimals at most. Is this intentional and if it is, should it be documented? |
Beta Was this translation helpful? Give feedback.
-
You can write @export_tool_button("Print Yea")
var some_func_right_after: Callable = func():
print("Yea") Also, would be useful to mention that the scene needs to be reloaded to get rid of Nil error:
|
Beta Was this translation helpful? Give feedback.
-
...and also call Btw, I'm finding it impossible to support undo-redo in such cases. I've read EditorPlugin.get_undo_redo but that one's limited to dedicated |
Beta Was this translation helpful? Give feedback.
-
Not sure if this has been discussed before, and I'm uncertain whether it adds any value, but I wanted to share something I discovered while experimenting with @export_group. I found that using "/" in the group name forces the creation of all subgroup levels down to where the next export variable is located, whereas using @export_subgroup only displays the final menu level if no previous levels contain exported variables. Thought this might be worth mentioning! ie: Image: GDscript: |
Beta Was this translation helpful? Give feedback.
-
Could we include a note about the timeline for @export var exported_val: float
func _init() -> void:
#exported_val isn't set yet and will be seen as null or zero depending on the type.
print(exported_val) #Prints `0` and not whatever is set in the inspector. Setting the value on the same line will allow the value to be used in @export var exported_val: float = 1
func _init() -> void:
print(exported_val) # Prints 1 A semi decent way around this is to use a setter to call a method, and avoid using # Set to 3 in the inspector.
@export var exported_val: float = 2:
set(val):
exported_val = val
print("Inspector Val: ", exported_val)
func _init() -> void:
print("Init Val: ", exported_val) Resulting in
|
Beta Was this translation helpful? Give feedback.
-
In Godot 4.5 the following Code does no longer work @export_tool_button("Hello", "Callable") var hello_action = hello The @export_tool_button("Hello") var hello_action = hello Edit: Okay nevermind I just had to reload the scene. But it still works without the Callabe. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
tutorials/scripting/gdscript/gdscript_exports
In Godot, class members can be exported. This means their value gets saved along with the resource (such as the scene) they're attached to. They will also be available for editing in the property e...
https://docs.godotengine.org/en/latest/tutorials/scripting/gdscript/gdscript_exports.html
Beta Was this translation helpful? Give feedback.
All reactions