Script Error: OnCollisionEnter2D
Hello,
I'm having the weirdest problem in Unity 5.4.1f1
I have a 2 2D sprite which fall one onto another. Both have Rigidbody 2D & Box Collider 2D. On of them has the following script attached:
using UnityEngine;
using System.Collections;
public class TestScript : MonoBehaviour
{
// Use this for initialization
void Start()
{
}
// Update is called once per frame
void Update()
{
}
void OnCollisionEnter2D(Collision2D col)
{
Debug.Log("TEST");
}
}
When compiling in VS - No errors appear. Unity, however, shows this message in the console:
Script error: OnCollisionEnter2D This message parameter has to be of type: The message will be ignored.
And sure enough - The function isn't being called.
When I double click the error it takes me to the OnCollisionEnter2D function, but I don't know what need I do to fix it. Can anyone see what's the problem here?
Thanks Nitay
Answer by romatallinn · Nov 12, 2016 at 09:07 PM
The code seems fine to me.
Make sure that in code you use "Collision2D col" as a parameter for a method, but not "Collider2D".
Try to close Unity and VS. Then open them again.
I've restarted everything. Didn't help... Does that script run okay at your end?
@nitaym Hm... I do not see any problems. The code works on my. Have you changed anything in rigidbody properties?
Nope. Looks like a bug I guess (at least the error message is). I've reported the bug
Your answer
Follow this Question
Related Questions
Music playing from 2 different scenes - how to fix? 1 Answer
2K screen resolution problem 0 Answers
Trouble with directing launched projectiles in Unity 2D 0 Answers
Player should turn in the direction the player is running. (2D Game) 0 Answers
Trouble with controlling the direction of projectiles with C# code 1 Answer