I am getting two very vague errors and I have had no idea whats wrong for some time now.
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?
Medial
April 21, 2023, 8:35am
2
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.
Hey Hey!
I’ve just completed this section of the course, however, I encountered an issue in the tutorial. I’ve resolved it myself, however, I’m not certain why my solution differs from Rick’s example.
Here is the code in question:
void OnCollisionEnter(Collision other)
For my OnCollisionEnter method, I receive the following error statement.
Script error: OnCollisionEnter
This message parameter has to be of type: Collision
The message will be ignored.
The solution was to change the r…
Thanks for your help.
2 Likes
Medial
April 21, 2023, 8:42pm
5
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
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
Medial
April 21, 2023, 8:52pm
8
It depends on what you want to do with this
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.
system
Closed
April 22, 2023, 8:53pm
10
This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.