Calling a function from another scene doesn't work as intended

Godot Version

4.3

Question

I have created functions that enable and disable collision shape. This seems to work fine when I tested it from within the scene but on trying to call the function on another scene it seems to not work properly.


ezgif-4-036ed8614a

So here if I press f it turns off collision and if I press g it turns on collision. It works fine and the collision works too and when collision is on and player passes by the shiny thing it plays the cutscene. But when I call it from another function it seems to call the turnOnCollisionShape function (I know this for sure because the debug message is called) but it doesn’t seem to turn on the collision shape for whatever reason as shown below.

This is another scene and turnOnCollisionShape and turnOffCollisionShape

ezgif-5-216317058e

The function is being called because its calling the right debug message but the collision shape doesn’t seem to work for some reason. What am I doing wrong?

Thanks in advance

If you are changing the collision shape during the physics tick/thread it may behave rudely. For some reason a lot of physics-based changes do not take during the physics thread. Try changing this to set_deferred

print("ne")
collision_shape_2d.set_deferred("disabled", true)
1 Like

Yeah this seems to work thanks allot! Is this an expected behavior? I also see that it works fine with signals? This is some weird behavior

Depends on if the signal is emitted from the physics thread and/or if the signal is connected by deferred. It probably is intended behaviour, presumably for optimizations.

1 Like

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.