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

Collisions not working in any version other than 2019.1.4f1

Discussion in 'Scripting' started by cheapcpps, Jan 8, 2021.

  1. cheapcpps

    cheapcpps

    Joined:
    Jul 15, 2020
    Posts:
    53
    I'm working on a vr game, but this is a general untiy question so it's going here.

    I'm using 2019.3 because its the earliest version that uses the vr api I need, I've noticed before when using old versions of unity, using collisions detections with OnCollisionEnter() { or OnCollisionExit() {, NEVER work. But it worked on 2019.1.4f1, I've done it twice on that version, worked both times, but not on any other version.

    I just made a test script to teleport you when a button is pushed, both the hand objects, and the buttons have colliders.

    However, neither Debug.Log returns ANYTHING, the OnCollisionExit method, just isn't being called, but htis exact same way worked on another version.

    I checked the docs and I should've done the Collision method correctly.

    Here's my button class.

    Edit: Yes, at least one of the objects have a rigidbody, I've tried switching weather it be on the button or the hands, and tried switching the collision type, and nothing worked.

    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4.  
    5. public class VRButton : MonoBehaviour
    6. {
    7.     public GameObject Player;
    8.     public GameObject LeftHand;
    9.     public GameObject RightHand;
    10.     public Vector3 TeleportPosition;
    11.  
    12.     public void OnCollisionExit(Collision collision)
    13.     {
    14.         Debug.Log("collision exit");
    15.         if (collision.gameObject == LeftHand || collision.gameObject == RightHand)
    16.         {
    17.             Debug.Log("washand");
    18.             Player.transform.position = TeleportPosition;
    19.         }
    20.     }
    21. }
    22.  
     
    Last edited: Jan 8, 2021
  2. cheapcpps

    cheapcpps

    Joined:
    Jul 15, 2020
    Posts:
    53
    I decided to go on my project I made on my laptop in 2019.1.4f1, and looked at the code, in that game, the player has a rigid body, the obstacle doesn not, the obstacle detects collisions the same way I did, so the code is indeed correct, just a case of unity being dumb, what am I doing wrong?
     
  3. cheapcpps

    cheapcpps

    Joined:
    Jul 15, 2020
    Posts:
    53
    I've found a work around, set both colliders to isTrigger, change "Collision collision" to "Collider collision" in your script, change "OnCollisionEnter" / Exit to "OnTriggerEnter" / exit, and it works