Search Unity

What is OnCollisionEx? Where is OnCollisionExit? and why does OnCollisionEx not work?

Discussion in 'Scripting' started by CloudyVR, Apr 28, 2017.

  1. CloudyVR

    CloudyVR

    Joined:
    Mar 26, 2017
    Posts:
    715
    I am trying to make a moving platform and parent my player whenever he is standing on a moving object.

    I am using Unity 5.6 and I can not find OnCollisionExit. So instead it seems that OnCollisionEx is the only option visible.

    When I try using OnCollisionEx it is never called, even though OnCollisionEnter works as expected.

    I even searched Google up and down trying to find even the slightest hint as to what OnCollisionEx was compared to OnCollisionExit but was unsuccessful and I only was able to find references to OnCollisionExit.

    How do I use it and why is it not being called?

    Thanks.
     
  2. UziMonkey

    UziMonkey

    Joined:
    Nov 7, 2012
    Posts:
    206
    What do you mean only option visible? The function must be called OnCollisionExit in order to work. It's not an override or anything, it's a Unity "magic" function that you just define and Unity knows what to do with.

    To get more information on these types of functions, refer to the MonoBehaviour reference.

    https://docs.unity3d.com/ScriptReference/MonoBehaviour.html
     
  3. CloudyVR

    CloudyVR

    Joined:
    Mar 26, 2017
    Posts:
    715
    Ok, it works but it was strange, I'm a sucker for using autocomplete and I always press ctrl+space when in MonoDevelop to see my options. When I did it this time it kept showing me a list containing OnCollisionEnter and OnCollisionEx. So there was a bug in the autocomplete list generation code or something.. Either way it worked after I just typed out OnCollisionExit in it's entirety.
     
  4. UziMonkey

    UziMonkey

    Joined:
    Nov 7, 2012
    Posts:
    206
    You may have spelled OnCollisionExit as OnCollisionEx somewhere else and that's where it's picking it up.

    I recommend ditching MonoDevelop though. It _never_ works right for me, especially tab completion. I've been using VS Code (a lightweight editor from Microsoft) for a while now and it always just works. If you want to go whole hog you can install Visual Studio it works really well but take like 6 gigs of hard drive space.
     
    monodokimes likes this.
  5. monodokimes

    monodokimes

    Joined:
    Feb 2, 2016
    Posts:
    24
    Visual Studio is purpose-built for writing C#, Monodevelop is a more general purpose IDE with much less intelligent code completion. Visual Studio directly analyses code to figure out what's available rather than best-guessing it based on your past behaviour.

    As a sidenote, Visual Studio is also jam-packed with other tools and keyboard shortcuts to make writing C# as easy as possible, you'll be surprised at how productive you can be with a little practice!
     
  6. StarManta

    StarManta

    Joined:
    Oct 23, 2006
    Posts:
    8,775
    Am I the only one that never has this sort of issue with MonoDevelop?
     
  7. Brathnann

    Brathnann

    Joined:
    Aug 12, 2014
    Posts:
    7,188
    Mono always gave me issues. The worst being when tabs would break if I had multiple scripts open, I couldn't switch between them. Constant crashes and many other issues. Our mac guy has all sorts of problems with it and I tell him to try one of the VS solutions that is on mac.

    Also note that Visual Studios now includes a install option in 2017 to install only what you need for Unity. Or, Unity 5.6 includes the option to install VS 2017, which I would assume does the same thing. Takes a lot less space than 6 gigs (mine is under a gig)