Objects instantiated via script not colliding

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

Forgive me if this is a very simple question!

I’m trying to make an Area2D collide with a ball (with a rigidbody2d attached).
I’m instantiating a line of these balls from another Node (named Line) through code but the signal isn’t being triggered.
Both have CollisionShape2D’s attached

If I add the ball in not through code, the signal kicks off.

I can’t find anything in the documentation to help with this?
Sorry if this isn’t enough info, if you need anymore happy to provide it!

:bust_in_silhouette: Reply From: Inces

perhaps You didn’t set collision layer of new area ? Or monitoring to true ?

Use REMOTE tab to examine your instanced Area. You can see it in top left corner of editor, right above scene tree. When You run project new option will appear there : Local/Remote. When You choose remote, You will see scene tree of your running project, with all areas instanced in code in realtime. Find out what is different about these areas and the ones You create in editor.

Thanks for answering!
I did more experimentation and it worked when I switched from RigidBody2D to KinematicBody2D?

Not 100% sure why this fixed it (assuming because I was updating the position directly rather than the physics engine, the collision wasn’t being detected?).

NoyesGames | 2021-12-13 00:15

Even when updating position manually collision will eventually be reported when bodies overlap, only their collision behavior will be broken. Kinematic body has less restrictive collision defaults. You can check if can_sleep was on with your rigid bodies.

Inces | 2021-12-13 12:24

can_sleep was on
When set to off it seems like it triggers the collision!

Thank you so much!

NoyesGames | 2021-12-13 13:53