0 votes

I need to make something every time some Spatial.translation changes. The trivial solution would be to write that_function(Spatial.translation) inside all the functions in which Spatial.translation changes.

I neither want to use a _process(delta) or similar function because it is a turn-based game.


Godot version 3.4
in Engine by (244 points)

Have you looked at setters and getters to help with your problem?

Could you give us more information on the operations you want to perform on each attribute modification

It seems that it does not work for my case since Spatial.translation is already defined:
var translation : Vector3 setget changeTranlation
The member 'translation' alredy exists in a parent class

I want to change Spatial.name everytime Spatial.translation changes. This Spatials are voxels in a voxel-based game, so it is sometimes useful that Spatial.name = var2str(Spatial.translation).

This days I had an idea so I do not need this feature, but not tested yet. Otherwise, it would be a good idea to know how to solve a similar problem, noticing that setget does not work for already defined variables (built-in).

1 Answer

+1 vote
Best answer

I'd use signals.
Create a signal:

signal translation_changed

in the ready function connect the signal to the script:


then, where you change your translatino you emit the signal:


and put your code to do stuff when it changed in a function called "_on_translatoin_changed", or how you decide to call it, just make sure its passed as the 3rd argument in the connect function.

by (110 points)
selected by

That would work. My first idea was to create a function like
func change_translation(vector): translation = vector do something with the translation
but your option is also good. In fact, I prefer your solution ;)


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.