Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Difference between OnCollisionEnter scripts.

Discussion in 'Editor & General Support' started by gamedev102020, Nov 16, 2020.

  1. gamedev102020

    gamedev102020

    Joined:
    Nov 4, 2020
    Posts:
    5
    Is there any difference between
    Code (CSharp):
    1. void OnCollisionEnter()
    2. {
    3.  
    4. }
    and
    Code (CSharp):
    1. private void OnCollisionEnter(Collision collision)
    2. {
    3.  
    4. }
    They are both working as intended but I am curious as to what is the difference between both of them.
     
  2. PraetorBlue

    PraetorBlue

    Joined:
    Dec 13, 2012
    Posts:
    7,697
    The default accessibility level in C# for a method is
    private
    , whether you explicitly write private or not makes no practical difference.

    Are you sure about that? My understanding is that the one that accepts a Collision parameter is the correct one, and Unity will only invoke that one.

    If Unity does invoke the one without a parameter, the only difference is that you now don't have any collision data to work with within your method.
     
  3. gamedev102020

    gamedev102020

    Joined:
    Nov 4, 2020
    Posts:
    5
    thanks! So yes, there is actually a difference between them and I found it out later.