• Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
  • Help Room /
avatar image
0
Question by BenStark · Jun 24, 2018 at 03:54 PM · buildbuild-errorwindowswindows 10comparetag

compareTag function not working in build version

I am creating a simple block fall game (v2018.1.4f1) when I test my game in the Unity Test Engine the code below works just fine. When I build the game for windows the compareTag method fails.

If I comment out "if (triggerCollider.gameObject.CompareTag("Cube"))" the code runs just fine on my Windows build. I have tried in both x86 and x86_64

I am fairly new to Unity and I am not sure if it's a problem with my scene or something else.

My Falling Block prefab is tagged as a Cube and it has the Box Collider 2D component with Is Trigger selected.

My Player component has the Box Collider 2D component and the Rigidbody 2 component. Under Rigid body component Simulated is Checked and Gravity Scale is set to 0 to keep it from falling.

     void OnTriggerEnter2D(Collider2D triggerCollider)
     {
         if (triggerCollider.gameObject.CompareTag("Cube"))
         {
             if (OnPlayerDeath != null)
             {
                 OnPlayerDeath();
             }
             Destroy(gameObject);
         }
     }

Comment
Add comment · Show 1
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image tormentoarmagedoom · Jun 26, 2018 at 10:28 AM 0
Share

try with

      if (triggerCollider.gameObject.tag ==("Cube"))

and say what you get.

And be sure the objects tag is Cube , not cube :D

0 Replies

· Add your reply
  • Sort: 

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Welcome to Unity Answers

The best place to ask and answer questions about development with Unity.

To help users navigate the site we have posted a site navigation guide.

If you are a new user to Unity Answers, check out our FAQ for more information.

Make sure to check out our Knowledge Base for commonly asked Unity questions.

If you are a moderator, see our Moderator Guidelines page.

We are making improvements to UA, see the list of changes.



Follow this Question

Answers Answers and Comments

155 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

CTD on Windows Build. Help me understand my report Log 0 Answers

The Visual Studio Solution generated by Unity is full of errors and I can't build it. Any solution for that? 0 Answers

My unity project only works on certain computers 0 Answers

The Assembly UnityEditor is referenced by Assembly-CSharp-firstpass ('Library/ScriptAssemblies/Assembly-CSharp-firstpass.dll'). But the dll is not allowed to be included or could not be found. 1 Answer

Build EXE - Crashes 0 Answers

  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges