Search Unity

  1. We are migrating the Unity Forums to Unity Discussions. On July 12, the Unity Forums will become read-only. On July 15, Unity Discussions will become read-only until July 18, when the new design and the migrated forum contents will go live. Read our full announcement for more information and let us know if you have any questions.

Resolved OnTriggerEnter Not Working in Builds, but working in PlayMode.

Discussion in 'Scripting' started by xmmywang, Oct 30, 2023.

  1. xmmywang


    Aug 11, 2023

    I currently have an event trigger object that has the Box Collider Component with IsTrigger = true.

    Everything works fine in the runtime of Unity Engine (PlayMode?). But When I build the project and run the executable application, all Colliders cannot detect events by the OnTriggerEnter() function.

    To be specific, the idea of this trigger object is that: when my cars pass by it, it can accelerate the speed of the car. So, I have the Inspector and the Script here for this event trigger object:
    upload_2023-10-30_16-13-28.png upload_2023-10-30_16-13-54.png

    I also have my cars Inspector here:
    upload_2023-10-30_16-14-31.png upload_2023-10-30_16-14-45.png

    If there is more information that I need to provide, please let me know. Thanks!
  2. CodeSmile


    Apr 10, 2014
    Do a development build. You are likely getting some exception that breaks scripts. You can also check the player.log.

    Also check for code that only runs in the editor, including playmode, but not in builds.
  3. xmmywang


    Aug 11, 2023
    Okay, I solved the problem by viewing the errors generated by Dev Build. Thanks to @CodeSmile !

    The Issue is that I'm receiving an error from the Mesh. So, there's no mesh Colliders from the cars to be detected by the event collider.

    CollisionMeshData couldn't be created because the mesh has been marked as non-accessible. Mesh asset path

    The error was caused by my c# scripts that generates the Cars:
    Code (CSharp):
    1. MeshCollider playerMS = player.AddComponent<MeshCollider>();
    2. playerMS.convex = true;
    So, what I did is I remove the code above and directly add the MeshCollider to the Prefabs.