0 votes

Hi All --
Could be a dumb question but is there a way to use the same collision mesh node for both: Area node's collision detection and actual physics body collision?
Having to duplicate each collision mesh to use it for those distinct purposes is a performance killer ...

in Engine by (389 points)

1 Answer

0 votes
Best answer

Shape and its derived classes are resources. Resources can be shared, so you can assign it to multiple CollisionShape nodes (i.e share it). You will need to create it only once and reduce memory usage, but it will cause twice as much processing in any case (just like it will if you have 10 nodes with the same shape).

I'm not sure what you expect to do in this situation, because if you have an Area and a Body with the same shape, in the same position and same collision masks/layers, they will basically trigger the same events at the same time redundantly, and will indeed be a waste. Better just listen to events from the body and not use an area (if they are configured the same).

by (27,595 points)
selected by

OK, I may be getting this whole thing wrong then but what I thought was that in order to get a collision to trigger an event you need to use an area node with a collision shape. When a body or something else enters said area, a signal is sent to a script and a function is triggered.
BUT, a collision shape attached to an area node that sends signals does not work as a physical collider (for rigid/vehicle/etc bodies to collide with, bounce off and so on). I need another collision shape for physical collisions.
Ie, if I want a rigid body to trigger a func when it hits a brick wall (static body) but also want that rigid body to bounce off of that wall, I need that wall object to have 2 collision shapes, one for area (signal) and one for collision.
Or it that not true and I can somehow use one collision mesh for both purposes?

Bodies emit events too when then enter in contact with other things: https://docs.godotengine.org/en/3.2/classes/class_rigidbody.html#signals

You would need an extra area only if you want to detect things within a different shape.

Hmm, so how do you detect collision of a rigid body with a static body? I tried:connect("body_entered", self, "_what_happens_on_crash")
I attached it to the rigid body. What happens function was also in the same script. In that function I said: if body.name == "obstacle": print sth. I then hit the rigid body into the obstacle object but the signal didn't work...

In the RigidBody inspector, enable Contact Monitor, and set Contacts Reported to at least 1.

I am glad I asked the question. I've now removed so much redundant collision geometry from my level and performance is through the roof!

Thank you!

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.