+2 votes

Just curious if you can disable a function, so you don't have to constantly check for something. It might be more efficient but Idk.

Instead of this

func _process(delta: float) -> void:
    if stopped:
        move(delta)


func move(delta: float):
    var collider = move_and_collide(dir * speed * delta)
    if collider:
        stopped = true

Something like this

func _physics_process(delta: float) -> void:
    move(delta)


func move(delta: float):
    var collider = move_and_collide(speed * delta)
    if collider:
        disable('move')
Godot version Godot 3.3.2
in Engine by (79 points)

1 Answer

+1 vote
Best answer

You dare insult the use of logic gates...

What you want to do can be done with some overrideable functions such as, set_process(false), set_input(false) and the same can be achieved using groups

add_to_group("moveable")

func _physics_process(delta: float) -> void:
    get_tree().call_group("moveable", delta)

func move(delta: float):
    var collider = move_and_collide(speed * delta)
    if collider:
        remove_from_group("moveable")

Or even better with signals. To be honest you're over complicating what can easily be achieved with a well placed if-else-then statement.

The best possible workflow for your intentions are State Machines so also have a look at that

by (4,972 points)
selected by

I'm not entirely sure why is this question insulting the use of logic gates...
But, State Machines would probably work.

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 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 webmaster@godotengine.org with your username.