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

Solved: Collision Problem. Works in one project but not another... Solved. Found the problem...

Discussion in 'Scripting' started by Jeremy-Borton, Dec 11, 2021.

Thread Status:
Not open for further replies.
  1. Jeremy-Borton

    Jeremy-Borton

    Joined:
    Oct 21, 2015
    Posts:
    63
    Hi, thanks for any help, I've been working on this bug for a week...

    My main project's collisions aren't working.
    I just tested a cube with a ridgebody and collider with gravity and so it falls on a plane with a mesh collider, but the cube goes right through the plane in my game... But in a new project the plane stops the cube from falling through. Using the same exact stuff I get different results. I don't know what's bugged out in my game. Any fixes when this happens?
    Same thing with any objects in my game, the collisions don't happen, and they used to work. I don't even get a debug log for OnCollisionEnter, or OnTriggerEnter, and the object just goes right through each other regardless of having ridgebodies and colliders, and layers set only on default.
    As a last resort I updated unity, that also didn't change anything.
    I'm doing basic stuff and I don't know, is there something that turns off collisions from occurring? Did I hit some button that did it?
    Do I need to scrap my whole project because the collisions won't work?
    I've tried everything I could find on google and tutorials, and I can't find a solution.
    I'm figuring I'm going to have to recreate everything in a new project if I can't fix it...
     
  2. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    36,713
    Oh yes, yes indeed! :) First of all, there is this:

    https://docs.unity3d.com/Manual/LayerBasedCollision.html

    Also, be sure that if you are moving Rigidbodies yourself that you ONLY move them by the .MovePosition() method, no other way. Do not move them by setting or translating the position. That will bypass collisions.
     
  3. Jeremy-Borton

    Jeremy-Borton

    Joined:
    Oct 21, 2015
    Posts:
    63
    Thanks, I'll look into .MovePosition()

    All my layers are on default, and I checked that already, so I don't think it's a layer problem. I haven't done anything with layers yet.
    Doesn't the rigidbody move with the object if gravity is on? All I do in both projects is create a cube with rigidbody and a plane under it, I set the cube to have gravity and hit play. In my game, the cube passes right through the plane, but in a new project the plane stops the cube from falling. And this is with no code involved. I don't get it...
     
  4. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    36,713
    Plane's are troublingly-thin colliders if you are not using continuous collision detection on the Rigidbodies.

    Try turning continuous collision on and if the problem goes away, that was it.
     
  5. Jeremy-Borton

    Jeremy-Borton

    Joined:
    Oct 21, 2015
    Posts:
    63
    nope, a cube with a collider and rigidbody with gravity falls right through a box collider. But it doesn't in a new project.
    Either I got to remake everything, or try packaging my game and importing it into a new project. Some setting must be messed up, and I don't know of a way to reset to defaults... I don't know.
     
  6. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    36,713
    That's easy: make a new project, shut Unity, remove that new project's Assets folder, and then copy your current project's Assets folder in, reopen Unity.
     
  7. Jeremy-Borton

    Jeremy-Borton

    Joined:
    Oct 21, 2015
    Posts:
    63
    Solved, I found the issue. It was in my code. I had copied this line of code into a Start method of an object, and thought it was referring to similar tags, when if fact it's referring to layers, not tags...of which all my objects are on the default layer...
    Code (CSharp):
    1. Physics.IgnoreLayerCollision(gameObject.layer, gameObject.layer);//anyone with similar layer tags, will not bump into each other.
    After Removing this line of code, all my collisions work. phew...
    yeah, I feel a little dumb, but I found the error, so that's good. Not giving up on a project is the main thing...
     
    Kurt-Dekker likes this.
  8. sillyninja65

    sillyninja65

    Joined:
    Dec 1, 2022
    Posts:
    9
    you feel dumb i cant even get to basic cubes to collide yet i am certain everything has been done correctly and im convinced it is a bug
     
  9. MelvMay

    MelvMay

    Unity Technologies

    Joined:
    May 24, 2013
    Posts:
    10,507
    Please don't necro posts like this. This thread is solved.
     
Thread Status:
Not open for further replies.