Search Unity

Physics bug: Collider behaves like a trigger (although the isTrigger flag is off)

Discussion in 'Physics' started by AkhmedAbasov, Feb 10, 2019.

  1. AkhmedAbasov

    AkhmedAbasov

    Joined:
    Mar 13, 2014
    Posts:
    163
    Unity 2018.2.7f1 (64-bit)

    For a long time I tried to understand what the problem was, until I realized that my BoxCollider without the isTrigger flag behaves like a trigger.

    To make sure that I am not crazy, I will show screenshots. Here is my object (car) in which I have disabled all triggers and colliders:
    12.png

    Here I turn on (only) BoxCollider:

    13.png

    And here is my simple script, which for some reason works:

    Code (CSharp):
    1.  
    2. private void OnTriggerEnter(Collider c)
    3.         {
    4.             isObstacleInFront = true;
    5.             obsObjName = c.gameObject.name;
    6.          
    7.         }
    8.  
    This is not supposed to work! I do not have triggers, Unity, which of us is crazy? And what is most interesting, what it interacts with is a trigger!
     
    Last edited: Feb 10, 2019
  2. NorthStar79

    NorthStar79

    Joined:
    May 8, 2015
    Posts:
    88
    can you please insert some Debug.Log()'s into this code. and share it with us?
     
  3. AkhmedAbasov

    AkhmedAbasov

    Joined:
    Mar 13, 2014
    Posts:
    163
    what do you want to show in debug?
     
  4. NorthStar79

    NorthStar79

    Joined:
    May 8, 2015
    Posts:
    88
    something like that would be enough :
    Code (CSharp):
    1. Debug.Log(c.gameObject.name);
     
  5. AkhmedAbasov

    AkhmedAbasov

    Joined:
    Mar 13, 2014
    Posts:
    163
    As I understood it as related to the layers of physics. I was able to repeat this behavior on a primitive cube. I have a layer car_ai, I assign it to a primitive cube.
    14.png

    TestGoCube script:

    Code (CSharp):
    1.  
    2. private void OnTriggerEnter(Collider c)
    3.     {
    4.         Debug.Log("TestGoCube Log: " + c.gameObject.name);
    5.  
    6.     }
    7.  
    Next in the physics settings I have the following division:

    15.png

    Objects that it detects are CarSpawnPoin (for example, the possible and others he will see).

    Debug
    TestGoCube Log: waypoint (3)
    0x0000000141536728 (Unity) StackWalker::GetCurrentCallstack
    0x000000014153CC66 (Unity) StackWalker::ShowCallstack
    0x000000014140BE3B (Unity) GetStacktrace
    0x00000001408AF5A0 (Unity) DebugStringToFile
    0x00000001418DB978 (Unity) DebugLogHandler_CUSTOM_Internal_Log
    0x0000000033682C4B (Mono JIT Code) (wrapper managed-to-native) UnityEngine.DebugLogHandler:Internal_Log (UnityEngine.LogType,string,UnityEngine.Object)
    0x0000000033682B34 (Mono JIT Code) [DebugLogHandler.cs:9] UnityEngine.DebugLogHandler:LogFormat (UnityEngine.LogType,UnityEngine.Object,string,object[])
    0x0000000033682435 (Mono JIT Code) [Logger.cs:47] UnityEngine.Logger:Log (UnityEngine.LogType,object)
    0x0000000033682156 (Mono JIT Code) [Debug.bindings.cs:98] UnityEngine.Debug:Log (object)
    0x0000000033682073 (Mono JIT Code) [TestGoCube.cs:13] TestGoCube:OnTriggerEnter (UnityEngine.Collider)
    0x0000000033681E09 (Mono JIT Code) (wrapper runtime-invoke) <Module>:runtime_invoke_void__this___object (object,intptr,intptr,intptr)
    0x00007FFE386A671B (mono) [mini.c:4937] mono_jit_runtime_invoke
    0x00007FFE385F8A71 (mono) [object.c:2623] mono_runtime_invoke
    0x0000000140C03B0A (Unity) scripting_method_invoke
    0x0000000140BFBEB0 (Unity) ScriptingInvocation::Invoke
    0x0000000140BB72ED (Unity) MonoBehaviour::HandleNotifications
    0x000000014059F3B4 (Unity) GameObject::SendMessageAny
    0x0000000140B4DAA5 (Unity) SendTriggerEvent
    0x0000000140B4C463 (Unity) PhysicsManager::processTriggerEnterExits
    0x0000000140B4FB02 (Unity) PhysicsManager::Simulate
    0x0000000140B47790 (Unity) `PhysicsManager::InitializeClass'::`2'::FixedUpdatePhysicsFixedUpdateRegistrator::Forward
    0x00000001409672B7 (Unity) ExecutePlayerLoop
    0x0000000140967366 (Unity) ExecutePlayerLoop
    0x0000000140969B4C (Unity) PlayerLoop
    0x000000014144B48A (Unity) PlayerLoopController::UpdateScene
    0x0000000141439F3D (Unity) PlayerLoopController::EnterPlayMode
    0x0000000141446528 (Unity) PlayerLoopController::SetIsPlaying
    0x0000000141449ADD (Unity) Application::TickTimer
    0x00000001415E85E5 (Unity) MainMessageLoop
    0x00000001415EA9D8 (Unity) WinMain
    0x000000014242EA6A (Unity) __scrt_common_main_seh
    0x00007FFE592213D2 (KERNEL32) BaseThreadInitThunk
    0x00007FFE59B754F4 (ntdll) RtlUserThreadStart


    For me at the moment it is not clear that - why does the collider work as a trigger? Do layer settings affect this?

    UPD. If you remove the car_ai layer, then everything is fine.
     
  6. AkhmedAbasov

    AkhmedAbasov

    Joined:
    Mar 13, 2014
    Posts:
    163
    Well, what are the ideas?
     
  7. NorthStar79

    NorthStar79

    Joined:
    May 8, 2015
    Posts:
    88
    I just created a project and set it up like yours. and did some tests but I could not reproduce your results. my Unity version is 2018.3.0f2
    you can try to update your unity version and see if it solves your problem. or you can try to create an empty project and try to isolate and reproduce this result. if you can reproduce this behaviour with a fresh project, we can be sure that this is a Unity bug. however if you cant reproduce same results with a fresh project, that means you have a problem with your project settings. in that case we can investigate your project deeply. if not, we can file a bug report and wait for eternity for a response from Unity.
     
  8. AkhmedAbasov

    AkhmedAbasov

    Joined:
    Mar 13, 2014
    Posts:
    163
    I will try to update, let you know what happened. In fact, how could the project settings affect the behavior of the collider? I still think this is a bug on the side of the engine.
     
  9. NorthStar79

    NorthStar79

    Joined:
    May 8, 2015
    Posts:
    88
    Agreed. but you will never know. Strange things always happen when using Unity.
     
  10. AkhmedAbasov

    AkhmedAbasov

    Joined:
    Mar 13, 2014
    Posts:
    163
    The update did not help. I now found that it reacts to objects whose collider is marked as a trigger. Also this only works if I use a layer. If you do not use a layer, then detection does not occur.
     
  11. AkhmedAbasov

    AkhmedAbasov

    Joined:
    Mar 13, 2014
    Posts:
    163
    Yes, I managed to recreate this situation in an empty project.
     

    Attached Files:

  12. AkhmedAbasov

    AkhmedAbasov

    Joined:
    Mar 13, 2014
    Posts:
    163
    Layers are not to blame here, it seems I do not understand how physics works and sending messages about stunts (
     
  13. AkhmedAbasov

    AkhmedAbasov

    Joined:
    Mar 13, 2014
    Posts:
    163
    This message is sent to the trigger Collider and the Rigidbody (if any) that the trigger Collider belongs to, and to the Rigidbody that touches the trigger.

    Understandably, apparently this is the case. But I do not want my collider (without a trigger flag) to receive messages that it collided with a trigger. My game object consists of a parent collider and child triggers. I want to receive only collision of triggers. How do I solve this? Do I need to filter by name?
     
  14. NorthStar79

    NorthStar79

    Joined:
    May 8, 2015
    Posts:
    88
    Oh, I see.
     But I do not want my collider (without a trigger flag) to receive messages that it collided with a trigger.

    Unfortunately, you can't do that as far as I know.
    But you are getting what collider is entered into trigger with 'OnTriggerEnter' you can control if that collider is intended collider or not by just simply checking its gameObject's tag or name etc.
     
  15. AkhmedAbasov

    AkhmedAbasov

    Joined:
    Mar 13, 2014
    Posts:
    163
    I decided this by checking now from the child trigger. Only now we have to look for the parent component, which will affect the speed.