SendMessage/OnCollisionEnter issue

Hi,

I’ve got two meshcolliders where one of them has a rigidbody. I’ve implemented it all with a class that does not inherit from MonoBehaviour (class Chunk). My Chunk class has a GameObject which I instantiate for each instance of my Chunk class. Everything works fine and there are working collisions between meshes.

However, now I want to detect if the objects collide using either “SendMessage” method on the GameObject or the OnCollisionEnter() function. But since I don’t inherit from MonoBehaviour, this is not working.

Any idea how I can get my callbacks working for collision detection using my approach?

for OnCollisionEnter to work you’ll need a script on the gameobject doing the collision. I.e. the “Chunk” instantiates the gameobject prefab which has the script component already attached to it (or you add it afterwards).

Sounds like you’ve created something similar to scriptableObjects to be honest…

I’ve only been working with Unity in couple of days so far. So could you please elaborate a bit on your answer? How can I attach a script to the gameobject? Do you mean creating a new class with MonoBehaviour inheritance and then add that as a component to my GameObject and this addition will have a OnCollisionEnter function?

I managed to get it working just as you said. Just had to process your explanation a bit more :slight_smile: Thanks!