OnCollisionEnter Not Working

Currently OnCollisionEnter says its unused (IDE0051), even though im following strictly on the Junior Programmer Mission, and im not sure why. The Box Collider is on if that’s useful. here’s the entire script.

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class PlayerController : MonoBehaviour
{
    private Rigidbody playerRb;
    public float jumpForce;
    public float gravityMultiplier;
    public bool isOnGround = true;
    // Start is called before the first frame update
    void Start()
    {
        playerRb = GetComponent<Rigidbody>();
        Physics.gravity *= gravityMultiplier;
    }

    // Update is called once per frame
    void Update()
    {

        if(Input.GetKeyDown(KeyCode.Space)&& isOnGround == true)
        {
            playerRb.AddForce(Vector3.up * jumpForce, ForceMode.Impulse);
            isOnGround = false;
        }
    }
    private void OnCollisonEnter(Collision collision)
    {
        isOnGround  = true;
    }
}

I started to type up a post about how it could be a bug in the editor extension, and then I realized after I had typed it all up that you have a typo in the name. You’re missing the second i.

2 Likes

It worked! Can’t believe I didn’t see that. Thanks!:slight_smile:

For all Unity’s magic functions like this, I suggest either:

  1. make sure your IDE is properly configured (see below) so that it suggests the spelling properly

  2. copy/paste it by hand from the documentation every single time.

Any other way is only going to waste way more time when your stuff misbehaves.

AND… when you get a warning, take it seriously. Prove to yourself that it’s not an issue rather than assuming it’s a false alarm.

As for setting up your IDE:

This may help you with intellisense and possibly other Visual Studio integration problems:

Sometimes the fix is as simple as doing Assets → Open C# Project from Unity. Other times it requires more.

Other times it requires you also nuke the userprefs and .vsconfig and other crufty low-value high-hassle files that Visual Studio tends to slowly damage over time, then try the above trick.

Barring all that, move on to other ideas:

https://discussions.unity.com/t/778503

Also, try update the package inside of Unity: Window → Package Manager → Search for Visual Studio Editor → Press the Update button

Depending on flavor and version of Visual Studio, it may also have an installation step that you perform within the actual Visual Studio. This step seems finicky at best and may require multiple openings of VS before it comes up.

Update: The VSCode extension has been deprecated and abandoned:

https://discussions.unity.com/t/886480

Update: the VSCode integration is back… maybe!?

https://discussions.unity.com/t/925353

There may be a community fork available that is receiving updates.

https://github.com/Chizaruu/com.tsk.ide.vscode

Also, this: https://discussions.unity.com/t/805330/7

Recently (July 2023) I worked on a Windows11 system that required a Microsoft component to be installed from within Visual Studio before it would work properly with all the OTHER software installed under Unity. I have no documentation on that process as I have only seen it once and it surprised me as well.