I've made many colliders before and that I used was collider other OnTriggerEnter collider other and then check if the other collider is the one I want by comparing TAG.
But this time I'm not triggering the canMelee boolean. My code:. So I wrote this code but somehow this doesn't work I checked the tag and added it to the player game object but it still doesn't work. I tried to add another debug to check if OnTriggerEnter is happening just above the if branch : Debug.
Log "Triggered" ; and it gets triggered. First double check that your enemy game objects have the tag "Enemy". Next make sure that your player collider has the "Is Trigger" option selected in the Unity inspector. Next try using col. CompareTag "Enemy" instead of: col. CompareTag method with example. Inside every if just debug what it is supposed to check and if its true, inside your void, make sure its running the void, etc Next: -Check if you have your object tagged as "Enemy", this can be on of the most common errors, and its so easy to solve, you may have written it wrong, or just not set it up.
Make sure you set all of this up, if this doesn't helped you, comment bellow, with prints, your gameobjects, codes, etc related to this. Learn more.Unity Collisions Tutorial - How To Use Colliders and Triggers in Unity - Unity 5 Tutorial
Unity collider trigger not working Ask Question. Asked 1 year, 10 months ago. Active 1 year, 9 months ago. Viewed 5k times. Log "Now you can do melee attack! I can't just figure put what's wrong. Please help me. Gaming Forever Gaming Forever 1 1 silver badge 9 9 bronze badges.
Have you tried debugging and placing a breakpoint on the if block? You can then check what the tag of "col" is by inspecting it. I suspect that maybe you have set the parent gameobject tag or something similar. Could you maybe post a screenshot of having the object selected? Can't tell you whats wrong, there are several things can cause this issue And several others like it.
We need to know your GameObjects Components. Include a screenshot of the 2 GameObjects Inspector.
Including their layers and tags. Also have you tried printing out col. Active Oldest Votes.Discussion in ' Physics ' started by BugKillerDec 9, Search Unity. Log in Create a Unity ID.
Unity Forum. Forums Quick Links. Asset Store Spring Sale starts soon! Unite Now has started! Come level up your Unity skills and knowledge. OnTriggerEnter2D stopped working. Joined: May 8, Posts: Hello, i'm using Version 5.
I can check the objects are colliding with a simple print to the console on OnTriggerStay2D but the collision is not triggered when it starts. The weird thing is that sometimes it works and others it doesn't. Another important thing is that I didn't change any of the objects' properties or code for more than one year and it stopped working with the last Unity updates.
This is my code: Code CSharp :. EnteredField. BugKillerDec 9, Joined: May 24, Posts: 2, I've not seen this reported before. Or are you trying to say that you don't get the OnTriggerEnter2D when you can see colliders overlapping but instead, get it a single physics update later?
Either way, I won't be able to help you easily without a bug report that has a simple reproduction case. Give me that and I can investigate immediately. MelvMayDec 9, Joined: Jun 25, Posts: I had the same problem.
The work around for me was adding a rigidbody2D, set kinematic to true. Then triggers worked. Sure, some more detail.
After I updated to the patch release v5.
Colliders randomly stops working
I found I needed to add a rigibody2d to make the triggers work.Search Unity. Log in Create a Unity ID. Unity Forum. Forums Quick Links. Asset Store Spring Sale starts soon! Unite Now has started! Come level up your Unity skills and knowledge. OnCollisionEnter not always firing? Joined: Sep 6, Posts: Is it normal for OnCollisionEnter to not register sometimes?
It is never called even though I can see the objects react to the collisions they are knocking around via physics. LostlogicOct 4, Joined: Apr 22, Posts: I believe the physics engine does collisions at a certain time in each frame.
IF one object moves thru another in the time between frames, then it will not be detected. So, when the collider or objects are too small, relative to their speed, they wont collide because one frame they haven't met yet and the next frame they have passed each other. Joined: Apr 5, Posts: 26, I guess otherwise the event could be removed from the queue again if it falls "too far behind" until it would be executed. DreamoraOct 4, Joined: Jul 19, Posts: 32, Eric5h5Oct 4, Joined: Dec 26, Posts: Do you move the colliders around without adding a rigidbody?
LostlogicOct 5, And the object that hit the colliders has a rigidbody attached right? Maybe you should create a small test project showing the bug and submit it with a bug report. Joined: Apr 5, Posts: How fast are the rigidbodies moving? As discussed on another thread here, there are velocities beyond which collisions will not be detected. You can see this by setting up simple scene where you bounce a ball off a wall.Search Unity.
Log in Create a Unity ID. Unity Forum. Forums Quick Links. Asset Store Spring Sale starts soon! Unite Now has started! Come level up your Unity skills and knowledge. Joined: Jul 27, Posts: Hi I am working on a school project with a group and since we don't have a lot of time, we use cubes with box colliders for basically everything.
And now when I've been playing a bit I noticed that sometimes the box colliders just stop working. The player can walk straight through them but raycasts seem to detect that they are there. The collider component is not set to trigger and is enabled. The worst part is that it is completely random and we can not foresee what block it will target next and we can't see if a block has been targeted unless we walk into it.
We've never seen anything like this before until we updated to Unity 5. And since we updated to Unity 5. I am currently taking it up to myself to test it in Unity 5. Since I need to play the level over and over again it will take some time.
But in the meantime, I would like to ask, has anyone else experienced this? Is this a Unity bug or something wrong with our game? Last edited: May 22, RealMTGMay 22, Joined: Nov 15, Posts: 5, JamesLeeNZMay 22, RealMTGMay 23, Collider components define the shape of a GameObject The fundamental object in Unity scenes, which can represent characters, props, scenery, cameras, waypoints, and more.
More info See in Glossary for the purposes of physical collisions. Meshes make up a large part of your 3D worlds.
Unity supports triangulated or Quadrangulated polygon meshes. Nurbs, Nurms, Subdiv surfaces must be converted to polygons. More info See in Glossary. A rough approximation of the mesh is often more efficient and indistinguishable in gameplay. The simplest and least processor-intensive colliders are primitive collider types. In 3D, these are the Box Collider A cube-shaped collider component that handles collisions for GameObjects like dice and ice cubes. More info See in GlossarySphere Collider A sphere-shaped collider component that handles collisions for GameObjects like balls or other things that can be roughly approximated as a sphere for the purposes of physics.
More info See in Glossary and Capsule Collider A capsule-shaped collider component that handles collisions for GameObjects like barrels and character limbs. You can add any number of these to a single GameObject to create compound colliders. Compound colliders approximate the shape of a GameObject while keeping a low processor overhead.
To get further flexibility, you can add additional colliders on child GameObjects. For instance, you can rotate boxes relative to the local axes of the parent GameObject. When you create a compound collider like this, you should only use one Rigidbody A component that allows a GameObject to be affected by simulated gravity and other forces. More info See in Glossary component, placed on the root GameObject in the hierarchy. Primitive colliders do not work correctly with shear transforms.
If you use a combination of rotations and non-uniform scales in the Transform hierarchy so that the resulting shape is no longer a primitive shape, the primitive collider cannot represent it correctly. There are some cases, however, where even compound colliders are not accurate enough.
In 3D, you can use Mesh Colliders A free-form collider component which accepts a mesh reference to define its collision surface shape. If you are used to working in 3D, Sprites are essentially just standard textures but there are special techniques for combining and managing sprite textures for efficiency and convenience during development.
More info See in Glossary graphic perfectly but you can refine the shape to any level of detail The Level Of Detail LOD technique is an optimization that reduces the number of triangles that Unity has to render for a GameObject when its distance from the Camera increases.
More info See in Glossary you like. These colliders are much more processor-intensive than primitive types, so use them sparingly to maintain good performance. Also, a mesh collider cannot collide with another mesh collider i. You can get around this in some cases by marking the mesh collider as Convex in the Inspector A Unity window that displays information about the currently selected GameObject, Asset or Project Settings, alowing you to inspect and edit the values.
The benefit of this is that a convex mesh collider can collide with other mesh colliders so you can use this feature when you have a moving character with a suitable shape. However, a good rule is to use mesh colliders for scene A Scene contains the environments and menus of your game. Think of each unique Scene file as a unique level. In each Scene, you place your environments, obstacles, and decorations, essentially designing and building your game in pieces.
More info See in Glossary geometry and approximate the shape of moving GameObjects using compound primitive colliders. You can add colliders to a GameObject without a Rigidbody component to create floors, walls and other motionless elements of a Scene.This is the 2nd game in the book and they didn't work for the first one either which was pong. The paddle just ends up clipping through the boundaries when you move it towards them.
All of the objects have a box collider so i have no idea what could be causing this and whether or not this was an intentional decision from the author. Everything works like its supposed to. The only problem is that when i move the paddle left or right or it travels straight through the field's borders.
Yes, that is what you need. In the example they use time. That is what they are limiting. Here, try this:. You can change '5' and '-5' to different values.
Attachments: Up to 2 attachments including images can be used with a maximum of To help users navigate the site we have posted a site navigation guide.
Make sure to check out our Knowledge Base for commonly asked Unity questions. Answers Answers and Comments. Trigger for reloading level won't work!
OnCollisionEnter() not always firing?
Colliders not working when used with a Rigidbody2D 1 Answer. Vuforia camera won't render shadows 0 Answers. LockCursor script not working as intended 3 Answers. Login Create account.
Ask a question. Add comment. Best Answer. GetAxis "Mouse X" ; transform. Translate h, 0, 0 ; transform. Clamp transform.Search Unity. Log in Create a Unity ID. Unity Forum. Forums Quick Links. Asset Store Spring Sale starts soon! Unite Now has started! Come level up your Unity skills and knowledge. Joined: Apr 30, Posts: I'm trying to write an automated test for my colliders, to make sure that the colliders are all set to reasonable values in my prefabs. In my test case, I Instantiate the prefab, add it to a wrapper gameobject with a RigidBody, and then call collider.
When the game is running, everything is working fine. In the test case, the collider.
Subscribe to RSS
This is true in the Rider debugger as well as via Debug. Log statements e. The MeshFilter for the graphic works fine. Pausing the Editor while running tests, everything looks fine. The Physics Visualizer shows the collider geometry fine. Things I have tried: - Adding yield return null between various calls - Calling Physics.
SyncTransforms One oddity is that the collider also does not return the attachedRigidBody - collider. In some objects there is scaling, some there isn't, doesn't seem to make any difference either in the game when running or in the tests.