This site is currently in read-only mode during migration to a new platform.
You cannot post questions, answers or comments, as they would be lost during the migration otherwise.
+2 votes

Unreal has a function called "construct" (or something similar, been a while) where the setting of a public variable (export in Godot) will update the object in the editor viewport. Effectively, it's a script that runs while the object is being edited, so you can add variables or logic that will show before you run the game. Is this possible in Godot?

Example:

I add an export variable called "is_red". If true, the sprite turns red. When I run the game, the change will show, but is there a way to show that change in the editor when I select the variable in the inspector?

Cheers!

in Engine by (78 points)

1 Answer

+3 votes
Best answer

The closest functionality allowing to do this would be the tool keyword.
Write it at the top of your script, and it will make the script run in the editor, just like it does in game.
See https://docs.godotengine.org/en/stable/tutorials/misc/running_code_in_the_editor.html

by (29,510 points)
selected by

That's perfect! Thank you. Very helpful.

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.