0 votes

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?

Godot version 3.4
in Engine by (12 points)

Please log in or register to answer this question.

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.