The Godot Q&A is currently undergoing maintenance!

Your ability to ask and answer questions is temporarily disabled. You can browse existing threads in read-only mode.

We are working on bringing this community platform back to its full functionality, stay tuned for updates.

godotengine.org | Twitter

+9 votes

what happened to export and setget in the new gdscript?

can someone give me an example?

Godot version latest
in Engine by (63 points)

remember to thumbs up as this is the 10th time i refer to this question.

1 Answer

+15 votes

nevermind i figured it out. example :

@export var surfaceColors: PackedFloat32Array = [1.0] :
    get:
        return surfaceColors
    set(value):
        surfaceColors = value
by (63 points)

This appears to be broken in the betas. I'm using beta 6 (I didn't try it until the betas, so I don't know if it ever worked in Godot 4). Does it still work for you?

@export var m_vecSize:Vector3 = Vector3(1,1,1) : set = setSize, get = getSize

func getSize():
print("Return size")
return m_vecSize

func setSize(a):
print("Change size")
m_vecSize = a

Neither getSize() nor setSize() get called when changing the value in the editor. The editor shows that the engine recognizes the change, but my set and get methods don't get called then.

Any ideas?

I am experiencing this issue as well in v4.0.2:

@tool
class_name CelestialBodyData extends Resource

@export_range(1, 20) var radius: int = 1:
    set(new_value):
        prints('SET: radius:', new_value)
        if not radius == new_value:
            radius = new_value
            emit_changed()

The value does change, but I never see the prints output, also, the emit_changed method does not fire.

Any thoughts or suggestions?

Thanks,
h4v0c

Maybe, if not radius == newvalue:, should be: if radius != newvalue:?

Yeah, lol, I don't know why I wrote it 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 [email protected] with your username.