Attention | Topic was automatically imported from the old Question2Answer platform. | |
Asked By | numberQ |
I’ve got an Area2D that I’m planning to instance frequently, and the collision shape of this area will be slightly different based on the values of certain exported vars. I figured it made sense to have a function that takes in those vars and calculates the collision polygon programmatically, rather than having to make a million different scenes for each minor variation.
My scene has an Area2D root node, with a child CollisionPolygon2D. The polygon has some dummy points I threw in. The script for my area node includes the following code:
var polygon = get_shape_points()
$CollisionPolygon2D.polygon = polygon
get_shape_points
just returns a PoolVector2dArray.
I have something in _draw
showing what my collision polygon actually is, and I can see that the polygon is indeed updating. But it’s not triggering any enter or exit signals! Strangely, when I don’t update the polygon programmatically and just rely on the dummy points I threw in via the editor, it does trigger signals. So it seems like I’m missing a step after setting the collision polygon.
Some Googling indicates there’s a function add_shape
that was useful in this scenario before, but it looks like that was deprecated. I’m not sure what replaced it, or if there’s a different design pattern altogether for doing something like this. Any tips?