Is it normal for "parameter has to be of type" error to NOT list the type?

I find it really weird that I’m getting this error:

“This message parameter has to be of type:”

But there is no type listed at all! That’s the entire error message!
(Unity 5.4)

Perhaps you can give us a little context?

I was trying out collision code for the first time, and copied code from somewhere (web or manual, I forget where). It was something like this (I’ve not bothered to include the contents of the function in this post):

void OnCollisionEnter2D(Collider2D coll) {}

I know now that Collider2D is the wrong type for OnCollisionEnter2D … but what my thread here is asking… is why Unity did not report the type that was needed? I googled and searched these forums and it seems like everyone else who encounters this beginner error gets the message with the correct type appended to the end, like this:

“This message parameter has to be of type: Collision2D”

But I get a blank instead. Is this normal?!? See image here:

2934829--217082--unity-type-error-blank.png

Unity 5.4.1f1 Personal
Windows 7 Home Premium, legal & up to date.

Here’s an example of someone else getting the error with type included:

Yes, normally it specifies the type. I wish you’d used the time it took to take & post screen shots to copy & paste the actual function instead. What you’ve typed above is syntactic nonsense, in both C# and JS. So I still don’t know what you’ve got.

My guess is that you’re using JavaScript (actually UnityScript), which is always a weird (and poorly-supported) beast, and that that’s why Unity can’t produce a better error in this case.

2 Likes

The one thing that jumps out at me is that the method signature of the code you’ve shown is invalid.

void OnCollisionEnter2D(Collider2D, coll) { ... }

When defining a method in C# (or UnityScript), parameters are defined using a type and a name. In this case, it looks like both are there, but separated by a comma. Instead of being interpreted as a type-name pair now, it’s thinking you’ve defined two parameters… Except one has only a type and no name, and the other has some crazy type that Unity can’t figure out.

I’m surprised you’re not getting an Unexpected Symbol error, rather than a Type error, though. Unless you’ve only just made up what you think the method was, rather than typing it out exactly as it is. This is a great lesson in how detail really matters when writing code.

4 Likes

I’ve since fixed my code so now I can’t remember if the comma was added from hand-typing, or if I copy-pasted it that way. (yes it’s C#) I’ll update this thread once I encounter the issue again. Thanks for your advice. I come from an Actionscript 3 background, so there may be some old habits creeping in to my approach.