Changing extents of CollisionShape2D causes collisions not to register

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By swordofbling

After going through my code I found that this bit of code causes the Area2D to not detect any collision.

get_node("P2goal/P2 goal/CollisionShape2D").shape.extents.y = 54

I have also turned on visible Collision Shapes in the Debug and the shape does change correctly, does the extents property cause the CollisionShape not to register collisions as I don’t get why this is causing the problem as when commented out it detects collisions normally.

This seems like a bug. I created a minimal reproduction project, but your line of code works fine for me (at least under Linux). What platform are you using? Does my minimal reproduction project work for you?

Jayman2000 | 2021-03-18 17:54

I tried your project and it seems to work, so I’ve changed it to kind of match what was going on in my game and I’ve recreated the issue it might be something to do with the process(delta) function but I’m not sure, project with the issue

swordofbling | 2021-03-18 18:18

I’ve figured out the cause of the issue if it is continuously trying to set the extents due to the _process(delta) function, the collision does not register as soon as it stops trying to change it is starts to work again. Not sure how to fix it though.

swordofbling | 2021-03-18 18:49

:bust_in_silhouette: Reply From: Jayman2000

Your code shouldn’t be in the _process() function. It should be in _physics_process().

Edit: It looks like your code can be in _process(). If you try to set the collision extents every time _process() is run, then it doesn’t work, but if you only try to set the collision extents sometimes then it does work:

func _process(delta):
    if Input.is_action_just_pressed("ui_accept"):
        pressed = !pressed
        var shape = get_node("P2goal/P2 goal/CollisionShape2D").shape
        if pressed:
            shape.extents.y = 54
        else:
            shape.extents.y = 32

That being said, I still feel like this behavior is a bug with Godot.

Thanks, it worked, can I ask why as I thought you only use the _physics_process for things like kinematic movement

swordofbling | 2021-03-18 20:34

I’ve been doing some research and I haven’t figured out why. I think that it has something to do with the order in which _process() and _physics_process() get run (see: Processing).

Jayman2000 | 2021-03-19 23:29