0
\$\begingroup\$

Seem to have exhausted google looking for an answer to a VERY bullet simple code that should work.

void onCollisionEnter(Collision col) {
    print ("hit " + col.gameObject.name);
    Destroy (gameObject);
    }

Bullet object has the above script, SphereCollider (radius a lot bigger than object), RigidBody, not a trigger, not kinematic, is travelling slow. All checked during runtime.

When it hits a wall (Box collider), it just bounces off but no collisionEnter code is ran.

Debug console bubble is on.

\$\endgroup\$

1 Answer 1

1
\$\begingroup\$

While you are trying to call onCollisionEnter(), MonoBehaviour uses the function OnCollisionEnter().

The difference is quite enormous, on the technical side of things. Being a function, the first letter should be a capital. By being lower case, your creating an entirely different function, that does not overload the original collision function your trying to call from MonoBehaviour.

To clarify, we are not overloading a method from MonoBehaviour, in the traditional sense. You should not use the override keyword, as this will report "no suitable method found to override".

\$\endgroup\$
7
  • \$\begingroup\$ I can't believe i overlooked that! Lesson learned, thanks \$\endgroup\$
    – herewego
    Aug 24, 2016 at 10:27
  • \$\begingroup\$ @herewego, its an easy mistake one has to make a few times to get into the right habits. Be sure to try it out and confirm thats your only problem, though. If it fixes it, be sure to accept the answer, so others know you found a solution. \$\endgroup\$
    – Gnemlock
    Aug 24, 2016 at 10:30
  • \$\begingroup\$ Yeah it worked, I have to wait a few mins till it allows me to accept answer though. Thanks again \$\endgroup\$
    – herewego
    Aug 24, 2016 at 10:31
  • \$\begingroup\$ I recommend to use the override keyword so compiler would emit an error if the method is not overriding the super class method. \$\endgroup\$ Aug 24, 2016 at 10:55
  • \$\begingroup\$ I mean, use override void onCollisionEnter(...) and then the compiler would give an error that there is no onCollisionEnter in MonoBehaviour. This is not dependent on the IDE, just a language feature that we can use. \$\endgroup\$ Aug 24, 2016 at 11:00

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .