Getting errors on collision enter and exit

I am getting two very vague errors and I have had no idea whats wrong for some time now.
image

private void OnCollisionEnter(Collider other)
    {
        print("Enter");
    }

    private void OnCollisionExit(Collider other)
    {
        print("hi");
    }

Does anyone know why I’m getting this and how to fix it?

You are passing wrong parameter types into OnCollision methods.

Replace “Collider” with “Collision”

1 Like

I see that this was wrong. But it doesn’t change the errors or the behavior.

I found out what was wrong. I called my class collision and that caused conflict.

Thanks for your help.

2 Likes

I see now, that your capsule collider is a trigger. With triggers you need to use OnTriggerEnter, because triggers don’t cause collisions.

Nevertheless, error should be different than before. Stupid question: did you save the script? It happens to me sometimes, that’s what I Ask :wink:

I also dont really know what is “print”, but if its not causing errors, I guess its all good. (I didnt encounter that with Unity before I think.)

Edit; Ah, yes, this solution makes sense, good one

2 Likes

If I turn off is trigger it becomes a collision object which I can’t move into. Should I just be using OnTriggerEnter?

1 Like

Nice work solving your own problem.

1 Like

It depends on what you want to do with this :slight_smile:
But generally this code you gave should not execute, according to collision action matrix. It is describing what colliders cause what actions upon interacting with other colliders, and is at the bottom od this page:

So if you want to only detect event with it, like check if player entered an area, you should use trigger. Collider (not triggered) is rather for collision event w (with some kind of physics involved).

And yes, for triggers you need to use OnTriggerEnter (etc) as far as I know.

Thank you.

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.

Privacy & Terms