- Home /
WTF is wrong! OnTrigger, OnCollision, nothing working!
So, all of a sudden in my project OnTrigger, OnCollision, Detect range, none of them would work. I tried copy pasting scripts, I tried following tutorials, I tried bare bone collision scene( Cube1[Has Collider set to IsTrigger, and Script] Cube2[Has collider, rigidbody, yes i tried even setting to is kinematic] moving Cube2 through Cube1, Regardless of what I try, Still nothing is working. I even went as far as re installing unity, deleting all my other projects off my computer, doing all updates for windows, restarting completely. Why wont anything work??
Here is the bare bone script for collision detection.
using UnityEngine;
using System.Collections;
public class Test : MonoBehaviour {
void OnTriggerEnter(Collider other)
{
Debug.Log("Shit be Working NOW??");
}
}
I am tempted to reinstall windows completely.. even tho i realllyyyy dont want to do that. (Takes for ever with all the drivers and updates for my custom computer.)
Check your Edit / Project settings / Physics matrix, see if something got accidentally unchecked
Have you checked the collision matrix in Project Settings --> Physics?
why would you reinstall windows.. unity is application software not system software.. it has nothing to do with it.. if you were going to reinstall anything it would be Unity, but regardless, i wouldnt do that anwyay..
If you build a sample project with a sphere and a box, both colliders set to 'isTrigger' and have the script above. What happens if you put a rigidbody on the sphere and shoot it at the cube? Does it work in a totally new project/scene?
Answer by JoshMBeyer · Mar 22, 2014 at 10:48 AM
Ok, so After going through what no programmer should ever have to endure(You will not believe the thing's I've done in the past two days...) After reinstalling windows, unity, visual studio, etc. I made a new project, 1 cube, 1 sphere, OnCollisionEnter, Attached rigidbody to the sphere, pressed play, moved the sphere into the cube and holy vector3 it worked. the cube was destroyed. STILL have issue with onTriggerEnter, but I feel Mel Gibson in Braveheart, yes that part with the paint on his face.
Ok OnTriggerEnter Is working. After reinstalling windows, and unity everything is going good so far. But I already tried reinstalling unity alone and that didnt work. Luckly enough things are in proper order now, I am going to sleep. "Posted at 5:49A$$anonymous$$"
Are you sure you didn't used two $$anonymous$$eshCollider? $$anonymous$$eshCollider can't collide with each other unless at least one of them is set to convex. Another issue could be that you changed the layer / layer collision mask so they don't collide. Another reason could be that you might have scaled your object with a negative value.
Things almost never happen out of the sudden. You might have changed something (maybe by accident) and didn't know that it might cause problems.
I never ever have heard of or experienced myself a case where reinstalling Unity or even Windows has fixed anything. There is a small possibility that something got corrupted in the Unity installation but the chance that something went wrong in the OS and had that result on Unity is 1:20000000
yes i am sure i was using a box collider and a sphere collider. BUT. I did try every other collider combination possible aswell. I mean it when i say i tried everything.
Answer by RyanZimmerman87 · Mar 22, 2014 at 05:41 AM
What do you mean all the sudden it stopped working? Did you ever even have it working before in your current project?
So you said:
"( Cube1[Has Collider set to IsTrigger, and Script] Cube2[Has collider, rigidbody, yes i tried even setting to is kinematic] moving Cube2 through Cube1"
It looks like from your description you got the IsTrigger set on the wrong object. You should remove the is trigger from the stationary Cube1 and put it on the Moving Cube2.
Your moving trigger object needs to have a collider, rigidbody, and isTrigger enabled.
Sounds like you did everything right except you need to swap the triggers you have it backwards.
That way your cube 1 will receive the trigger collision in your script.
I'm not a documentation guru (actually really bad at studying) so hopefully I'm not mixed up here but I've always used the trigger object on the moving one, I'm pretty sure that's how it works.
But I think the script can be on either object. What's important is that only one of them is a trigger object and that's the one that is moving, has a collider, and rigid body.
Yes I've tried that aswell. I mean I literally tried every possible combination. Nothing is working. Yes, I had Ontrigger, and Oncollision working already. Was working just fine. Then all of a sudden my player was reset completely to defaults, the fps_arms were scaled down dramaticly, my scripts folder(Including scripts) were deleted. I was testing the scene for a lasersight on the $$anonymous$$4 weapon. After i stoped the game, all that happened. Bullets stopped triggering since the scripts were deleted. I re scripted everything and then noticed none of the OnTrigger, OnCollision, Range Detection, none of them would register events. So I created a new project with just the cubes, and then with a cube and a sphere, tried every possible combiination of the requirements for the OnTrigger, etc. and still nothing.
I've had similar problems with random resets of gameobjects and deleted asset. I have no idea why it happens but sometimes it does. this is why i figured i need to reinstall windows its self because idk i am just on my last limb here its been 2 days of this issue and trouble shooting something so simple to create(Refering to the cube and sphere collision detection) I even posted a video screen cast to show I am doing nothing wrong and everyone said yes it should definitely be triggering my debug.log but its not
I mean I am willing to get on TeamViewer to let someone else try cause its seriously not because something I am doing wrong.
Hmm that's very strange, not really sure what could cause that now.
Does a new project work? $$anonymous$$aybe some of your build settings got messed up?
Sounds very frustrating I hope you get it all sorted out. If it is just isolated to that project and not Unity itself you should be able to fix it if you find the right setting(s) that got messed up.
$$anonymous$$aybe you accidentally deleted some stuff or loaded up the wrong project file? I'm not sure how all that stuff would just disappear like that but certainly anything is possible with technology these days.
I would first try creating a new empty project with just 2 objects to see if it works.
If that works I would go back to your current project and check literally every single object and child component in the scene hierarchy list. You may just have one little unwanted script or mystery collider etc that's messing up everything.
Also you should always keep at the very least one but most likely several back up projects in case anything like this happens. And store it on a different hard drive just in case one dies.
I did try a new project. I deleted all my projects off my computer, Uninstalled unity, reinstalled unity, created a new projects with 2 gameobjects, tested it and still did not work. I have no idea what is wrong. So... I did the unwanted and whiped out my computer, doing updates, hoping it will work now. If not, I am walking to the nearest gun store, getting a rocket launcher and shooting my computer.. twice..