0 votes

I know that in Unity, when something is changed in the editor, OnValidate() is called. Is there something similar in godot ? I have a Planet node containing a script with a generatePlanet() function. this function uses resources given to the node to create a mesh for the planet and I'd like to be able to see this mesh in the editor and not only when the game runs.

in Engine by (83 points)

1 Answer

+1 vote
Best answer

Yes, you can do that. In fact, any bahaviour that works in-game can also work in the editor. However, this is not the default behaviour. You need to write a script to enable it. Those scripts inherit from a class called EditorScript and they allow you to make changes to your game from the editor without running them. Here are the docs, here an here are a two videos.

Basically what you want to do is create a script that runs from within the editor whenever you input a resource file in the corresponding field.

Follow GDQuest's tutorial

1) Create a new script and write the keyword tool on the first line.
2) Inherit from EditorScript
3) Create export variables which are going to hold the resources for your generatePlanet() function. use the setget keyword followed by the name of the generatePlanet() function in order to have the script update in the editor every time a resource file changes.

If this helps you, please mark this answer as best so that others can find it useful too.

by (1,869 points)
selected by

I don't quite get how to use that getset keyword, could you give an example please ?

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.