+1 vote

I was trying to prevent the change of certain properties of a node in tool mode, and most things I've tried haven't resulted in anything.

Right now I'm trying

func _set(property, value):

    if(property == "transform/pos"):
        set(property, Vector2(0, 0))

However this crashes Godot. -_-

Is there a more straightforward way that I'm overlooking?

in Engine by (5,274 points)

1 Answer

+1 vote

You can use setget to make variables behave like properties: https://godotengine.org/qa/8704/there-way-tell-tool-scripts-exported-variables-get-updated

by (29,090 points)

How would I do that on built in properties such as a node transform? I'm not sure what that looks like.

I believe you can use the _notification function and get something like NOTIFICATION_TRANSFORM_CHANGED or NOTIFICATION_LOCAL_TRANSFORM_CHANGED for Spatial and CanvasItem.

Spatial also has a set_notify_local_transform but is not documented its use.

Thanks. I tried that out this morning and it wasn't quite working, going back to it to double check though, it seems to be recognizing the notifications properly.

It works now. The one thing to add though is there needs to be a flag involved, or you can trap yourself in non-stop notification loop. As the transform itself will fire off another transformation notification.

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.