OnTriggerEnter2D and OnCollisionEnter2D not triggering in console

Observed Behavior
In lecture 70 when using OnTriggerEnter2D, OnCollisionEnter2D with print, there is no message on neither collision nor on when there would be Trigger.

Expected Behavior
Obviously, there’s supposed to be SOME message in console. (either “Collision” or “Trigger”)

What I’ve tried:

I’ve been through the code many times, there’s not a lot to mess up on.
Watched the lecture three times to see if I missed something

Here’s my code:

halp pls

1 Like

Have you added this script as a component to the LoseCollider game object?

Is your script filename the same as the class, I notice that you have called the class LoseColider, the same with your variable of colision in the OnCollisionEnter2D() method, e.g. missing the second letter L in both cases. Scripts and classes are required to the same name.

Some things to check. :slight_smile:

Hey thanks for quick reply! Unfortunately, everything and I mean EVERYTHING crashed on me so I had to rebuild the scene (here’s a lesson about not saving). While on that I made a new object and script this time making sure to keep things you mentioned in mind but, sadly, the issue is still the same :frowning:
For whatever reason all my objects have “Z” value showing in Unity (unlike in course video). Think it’s related?

1 Like

Hey thanks for quick reply!

You’re very welcome :slight_smile:

For whatever reason all my objects have “Z” value showing in Unity (unlike in course video). Think it’s related?

Quite possibly yes, if you consider the objects in that 2D game to be like pages of a book, some are behind others, some are in front of others… you’d want the objects you are testing for collisions on to be the same as the collider…

Screenshot?

Oh, right! Sorry! Here it is:


and

As you can see the relevant values are right… or are they? I have gone through it several times now but found nothing.

1 Like

Yep - so you have the ball on a Z index of zero, but the lose collider is on -2… they won’t touch :slight_smile:

Change the Z index of the lose collider to zero also and give it another go :slight_smile:

Nope. still not working. Tried few different values but nothing works.

1 Like

Sorry, just had a power cut so lost internet access briefly!

You have a script file name of LooseCollider.cs and a class called LoseColider

They need to be called the same thing, so, perhaps for now, rename the class to LooseCollider, e.g.;

public class LooseCollider : MonoBehaviour {

…then make sure it is still attached to the LooseCollider game object when you go back into Unity.

The thing is they are! As I said, I made a new script (this time doing everything like in the course).

ah, ok, sorry, I was going by the screenshots… if you can zip up the project and make it available for me to download I will happily take a look for you.

On the LoseCollider you’re using a 3D Box collider, it won’t interact with the 2D Circle Collider.

Change it to a Box Collider 2D, everything’ll work fine.

1 Like

YES it worked! Thank you!

1 Like

Completely missed that… lol…!

1 Like

Google skills not useful here!

1 Like

Thanks Galandil I have no idea how the 3D collider was there! Solved my problem too. Cheers