How to log game objects colliding in Unity












0















This is my first unity project so I am fairly unfamiliar with everything the platform has. I am trying to log a message to the console when I have a my player game object run into a finish line. Both objects have Box Colliders on them and I have attached a C# script to the player object. Below is the code I have currently.



 void OnCollisionEnter2D(Collision2D col)
{
if (col.gameObject.tag == "Finish")
{
Debug.Log("Finish");


}
}


The problem is that when I move the player into the "Finish" object no logging appears inside the console.
Thanks in Advance!



This is the main player inspector tab



This is the finish line inspector tab










share|improve this question

























  • Have you verified the tag?

    – bolkay
    Nov 13 '18 at 21:05






  • 1





    What happens when you debug it?

    – Clayton Harbich
    Nov 13 '18 at 21:07











  • Does the player have a Rigidbody?

    – Oriol Miró
    Nov 13 '18 at 21:25













  • The player has a ridgidbody

    – tflores
    Nov 13 '18 at 21:38






  • 1





    Show Inspector tab screenshot of the object.

    – Programmer
    Nov 13 '18 at 21:46
















0















This is my first unity project so I am fairly unfamiliar with everything the platform has. I am trying to log a message to the console when I have a my player game object run into a finish line. Both objects have Box Colliders on them and I have attached a C# script to the player object. Below is the code I have currently.



 void OnCollisionEnter2D(Collision2D col)
{
if (col.gameObject.tag == "Finish")
{
Debug.Log("Finish");


}
}


The problem is that when I move the player into the "Finish" object no logging appears inside the console.
Thanks in Advance!



This is the main player inspector tab



This is the finish line inspector tab










share|improve this question

























  • Have you verified the tag?

    – bolkay
    Nov 13 '18 at 21:05






  • 1





    What happens when you debug it?

    – Clayton Harbich
    Nov 13 '18 at 21:07











  • Does the player have a Rigidbody?

    – Oriol Miró
    Nov 13 '18 at 21:25













  • The player has a ridgidbody

    – tflores
    Nov 13 '18 at 21:38






  • 1





    Show Inspector tab screenshot of the object.

    – Programmer
    Nov 13 '18 at 21:46














0












0








0








This is my first unity project so I am fairly unfamiliar with everything the platform has. I am trying to log a message to the console when I have a my player game object run into a finish line. Both objects have Box Colliders on them and I have attached a C# script to the player object. Below is the code I have currently.



 void OnCollisionEnter2D(Collision2D col)
{
if (col.gameObject.tag == "Finish")
{
Debug.Log("Finish");


}
}


The problem is that when I move the player into the "Finish" object no logging appears inside the console.
Thanks in Advance!



This is the main player inspector tab



This is the finish line inspector tab










share|improve this question
















This is my first unity project so I am fairly unfamiliar with everything the platform has. I am trying to log a message to the console when I have a my player game object run into a finish line. Both objects have Box Colliders on them and I have attached a C# script to the player object. Below is the code I have currently.



 void OnCollisionEnter2D(Collision2D col)
{
if (col.gameObject.tag == "Finish")
{
Debug.Log("Finish");


}
}


The problem is that when I move the player into the "Finish" object no logging appears inside the console.
Thanks in Advance!



This is the main player inspector tab



This is the finish line inspector tab







c# unity3d






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 13 '18 at 22:12







tflores

















asked Nov 13 '18 at 21:03









tflorestflores

11




11













  • Have you verified the tag?

    – bolkay
    Nov 13 '18 at 21:05






  • 1





    What happens when you debug it?

    – Clayton Harbich
    Nov 13 '18 at 21:07











  • Does the player have a Rigidbody?

    – Oriol Miró
    Nov 13 '18 at 21:25













  • The player has a ridgidbody

    – tflores
    Nov 13 '18 at 21:38






  • 1





    Show Inspector tab screenshot of the object.

    – Programmer
    Nov 13 '18 at 21:46



















  • Have you verified the tag?

    – bolkay
    Nov 13 '18 at 21:05






  • 1





    What happens when you debug it?

    – Clayton Harbich
    Nov 13 '18 at 21:07











  • Does the player have a Rigidbody?

    – Oriol Miró
    Nov 13 '18 at 21:25













  • The player has a ridgidbody

    – tflores
    Nov 13 '18 at 21:38






  • 1





    Show Inspector tab screenshot of the object.

    – Programmer
    Nov 13 '18 at 21:46

















Have you verified the tag?

– bolkay
Nov 13 '18 at 21:05





Have you verified the tag?

– bolkay
Nov 13 '18 at 21:05




1




1





What happens when you debug it?

– Clayton Harbich
Nov 13 '18 at 21:07





What happens when you debug it?

– Clayton Harbich
Nov 13 '18 at 21:07













Does the player have a Rigidbody?

– Oriol Miró
Nov 13 '18 at 21:25







Does the player have a Rigidbody?

– Oriol Miró
Nov 13 '18 at 21:25















The player has a ridgidbody

– tflores
Nov 13 '18 at 21:38





The player has a ridgidbody

– tflores
Nov 13 '18 at 21:38




1




1





Show Inspector tab screenshot of the object.

– Programmer
Nov 13 '18 at 21:46





Show Inspector tab screenshot of the object.

– Programmer
Nov 13 '18 at 21:46












3 Answers
3






active

oldest

votes


















3














Your script attached to the player checks for a collision with an object with the tag "Finish". Your Object "Finish Line" has tag "untagged". You have to add a tag "Finish" to it to see it working.






share|improve this answer
























  • This worked, thank you for the help!

    – tflores
    Nov 13 '18 at 23:23






  • 1





    @tflores you should mark this as answered, if it solved your problem. So others know as well.

    – JTizzle
    Nov 14 '18 at 0:57



















2














With the updated question and screenshots, the problem is that you're checking for the "Finish" tag but the "Finish" GameObject's tag is set to "Untagged" so the if (col.gameObject.tag == "Finish") statement will not evaluate to true.



You have two options:



1. Select the "Finish" GameObject, click the tag that says "Untagged" and create new tag named "Finish". If you already have this tag, change the tag of the "Finish" GameObject from "Untagged" to "Finish" and your if (col.gameObject.tag == "Finish") code should work.





2. If you did not intend to use tag then just compare the GameObject by name instead of tag by simply replacing if (col.gameObject.tag == "Finish") with if (col.gameObject.name == "Finish").



If none of the two options above worked for you then OnCollisionEnter2D is not being called at-all. Put a Debug.Log outside the if statement like below and leave a comment about if there is a log or not.



void OnCollisionEnter2D(Collision2D col)
{
Debug.Log("Finish: " + col.gameObject.name);
}





share|improve this answer































    0














    Just first idea that came in mind:
    - Did you add colliders on both of objects that should collide?
    Without them engine will not generate events of colliding at all.






    share|improve this answer
























    • Yes they both have colliders, when I move the one object into the other, it will "bounce off" each other as well. But I do not receive a log message saying they have hit each other.

      – tflores
      Nov 13 '18 at 21:43











    Your Answer






    StackExchange.ifUsing("editor", function () {
    StackExchange.using("externalEditor", function () {
    StackExchange.using("snippets", function () {
    StackExchange.snippets.init();
    });
    });
    }, "code-snippets");

    StackExchange.ready(function() {
    var channelOptions = {
    tags: "".split(" "),
    id: "1"
    };
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function() {
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled) {
    StackExchange.using("snippets", function() {
    createEditor();
    });
    }
    else {
    createEditor();
    }
    });

    function createEditor() {
    StackExchange.prepareEditor({
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader: {
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    },
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    });


    }
    });














    draft saved

    draft discarded


















    StackExchange.ready(
    function () {
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53289464%2fhow-to-log-game-objects-colliding-in-unity%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    3 Answers
    3






    active

    oldest

    votes








    3 Answers
    3






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    3














    Your script attached to the player checks for a collision with an object with the tag "Finish". Your Object "Finish Line" has tag "untagged". You have to add a tag "Finish" to it to see it working.






    share|improve this answer
























    • This worked, thank you for the help!

      – tflores
      Nov 13 '18 at 23:23






    • 1





      @tflores you should mark this as answered, if it solved your problem. So others know as well.

      – JTizzle
      Nov 14 '18 at 0:57
















    3














    Your script attached to the player checks for a collision with an object with the tag "Finish". Your Object "Finish Line" has tag "untagged". You have to add a tag "Finish" to it to see it working.






    share|improve this answer
























    • This worked, thank you for the help!

      – tflores
      Nov 13 '18 at 23:23






    • 1





      @tflores you should mark this as answered, if it solved your problem. So others know as well.

      – JTizzle
      Nov 14 '18 at 0:57














    3












    3








    3







    Your script attached to the player checks for a collision with an object with the tag "Finish". Your Object "Finish Line" has tag "untagged". You have to add a tag "Finish" to it to see it working.






    share|improve this answer













    Your script attached to the player checks for a collision with an object with the tag "Finish". Your Object "Finish Line" has tag "untagged". You have to add a tag "Finish" to it to see it working.







    share|improve this answer












    share|improve this answer



    share|improve this answer










    answered Nov 13 '18 at 22:16









    Łukasz DrzenslaŁukasz Drzensla

    313




    313













    • This worked, thank you for the help!

      – tflores
      Nov 13 '18 at 23:23






    • 1





      @tflores you should mark this as answered, if it solved your problem. So others know as well.

      – JTizzle
      Nov 14 '18 at 0:57



















    • This worked, thank you for the help!

      – tflores
      Nov 13 '18 at 23:23






    • 1





      @tflores you should mark this as answered, if it solved your problem. So others know as well.

      – JTizzle
      Nov 14 '18 at 0:57

















    This worked, thank you for the help!

    – tflores
    Nov 13 '18 at 23:23





    This worked, thank you for the help!

    – tflores
    Nov 13 '18 at 23:23




    1




    1





    @tflores you should mark this as answered, if it solved your problem. So others know as well.

    – JTizzle
    Nov 14 '18 at 0:57





    @tflores you should mark this as answered, if it solved your problem. So others know as well.

    – JTizzle
    Nov 14 '18 at 0:57













    2














    With the updated question and screenshots, the problem is that you're checking for the "Finish" tag but the "Finish" GameObject's tag is set to "Untagged" so the if (col.gameObject.tag == "Finish") statement will not evaluate to true.



    You have two options:



    1. Select the "Finish" GameObject, click the tag that says "Untagged" and create new tag named "Finish". If you already have this tag, change the tag of the "Finish" GameObject from "Untagged" to "Finish" and your if (col.gameObject.tag == "Finish") code should work.





    2. If you did not intend to use tag then just compare the GameObject by name instead of tag by simply replacing if (col.gameObject.tag == "Finish") with if (col.gameObject.name == "Finish").



    If none of the two options above worked for you then OnCollisionEnter2D is not being called at-all. Put a Debug.Log outside the if statement like below and leave a comment about if there is a log or not.



    void OnCollisionEnter2D(Collision2D col)
    {
    Debug.Log("Finish: " + col.gameObject.name);
    }





    share|improve this answer




























      2














      With the updated question and screenshots, the problem is that you're checking for the "Finish" tag but the "Finish" GameObject's tag is set to "Untagged" so the if (col.gameObject.tag == "Finish") statement will not evaluate to true.



      You have two options:



      1. Select the "Finish" GameObject, click the tag that says "Untagged" and create new tag named "Finish". If you already have this tag, change the tag of the "Finish" GameObject from "Untagged" to "Finish" and your if (col.gameObject.tag == "Finish") code should work.





      2. If you did not intend to use tag then just compare the GameObject by name instead of tag by simply replacing if (col.gameObject.tag == "Finish") with if (col.gameObject.name == "Finish").



      If none of the two options above worked for you then OnCollisionEnter2D is not being called at-all. Put a Debug.Log outside the if statement like below and leave a comment about if there is a log or not.



      void OnCollisionEnter2D(Collision2D col)
      {
      Debug.Log("Finish: " + col.gameObject.name);
      }





      share|improve this answer


























        2












        2








        2







        With the updated question and screenshots, the problem is that you're checking for the "Finish" tag but the "Finish" GameObject's tag is set to "Untagged" so the if (col.gameObject.tag == "Finish") statement will not evaluate to true.



        You have two options:



        1. Select the "Finish" GameObject, click the tag that says "Untagged" and create new tag named "Finish". If you already have this tag, change the tag of the "Finish" GameObject from "Untagged" to "Finish" and your if (col.gameObject.tag == "Finish") code should work.





        2. If you did not intend to use tag then just compare the GameObject by name instead of tag by simply replacing if (col.gameObject.tag == "Finish") with if (col.gameObject.name == "Finish").



        If none of the two options above worked for you then OnCollisionEnter2D is not being called at-all. Put a Debug.Log outside the if statement like below and leave a comment about if there is a log or not.



        void OnCollisionEnter2D(Collision2D col)
        {
        Debug.Log("Finish: " + col.gameObject.name);
        }





        share|improve this answer













        With the updated question and screenshots, the problem is that you're checking for the "Finish" tag but the "Finish" GameObject's tag is set to "Untagged" so the if (col.gameObject.tag == "Finish") statement will not evaluate to true.



        You have two options:



        1. Select the "Finish" GameObject, click the tag that says "Untagged" and create new tag named "Finish". If you already have this tag, change the tag of the "Finish" GameObject from "Untagged" to "Finish" and your if (col.gameObject.tag == "Finish") code should work.





        2. If you did not intend to use tag then just compare the GameObject by name instead of tag by simply replacing if (col.gameObject.tag == "Finish") with if (col.gameObject.name == "Finish").



        If none of the two options above worked for you then OnCollisionEnter2D is not being called at-all. Put a Debug.Log outside the if statement like below and leave a comment about if there is a log or not.



        void OnCollisionEnter2D(Collision2D col)
        {
        Debug.Log("Finish: " + col.gameObject.name);
        }






        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Nov 14 '18 at 1:59









        ProgrammerProgrammer

        76.3k1086151




        76.3k1086151























            0














            Just first idea that came in mind:
            - Did you add colliders on both of objects that should collide?
            Without them engine will not generate events of colliding at all.






            share|improve this answer
























            • Yes they both have colliders, when I move the one object into the other, it will "bounce off" each other as well. But I do not receive a log message saying they have hit each other.

              – tflores
              Nov 13 '18 at 21:43
















            0














            Just first idea that came in mind:
            - Did you add colliders on both of objects that should collide?
            Without them engine will not generate events of colliding at all.






            share|improve this answer
























            • Yes they both have colliders, when I move the one object into the other, it will "bounce off" each other as well. But I do not receive a log message saying they have hit each other.

              – tflores
              Nov 13 '18 at 21:43














            0












            0








            0







            Just first idea that came in mind:
            - Did you add colliders on both of objects that should collide?
            Without them engine will not generate events of colliding at all.






            share|improve this answer













            Just first idea that came in mind:
            - Did you add colliders on both of objects that should collide?
            Without them engine will not generate events of colliding at all.







            share|improve this answer












            share|improve this answer



            share|improve this answer










            answered Nov 13 '18 at 21:29









            Rustam AshurovRustam Ashurov

            614




            614













            • Yes they both have colliders, when I move the one object into the other, it will "bounce off" each other as well. But I do not receive a log message saying they have hit each other.

              – tflores
              Nov 13 '18 at 21:43



















            • Yes they both have colliders, when I move the one object into the other, it will "bounce off" each other as well. But I do not receive a log message saying they have hit each other.

              – tflores
              Nov 13 '18 at 21:43

















            Yes they both have colliders, when I move the one object into the other, it will "bounce off" each other as well. But I do not receive a log message saying they have hit each other.

            – tflores
            Nov 13 '18 at 21:43





            Yes they both have colliders, when I move the one object into the other, it will "bounce off" each other as well. But I do not receive a log message saying they have hit each other.

            – tflores
            Nov 13 '18 at 21:43


















            draft saved

            draft discarded




















































            Thanks for contributing an answer to Stack Overflow!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid



            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.


            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53289464%2fhow-to-log-game-objects-colliding-in-unity%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            Bressuire

            Vorschmack

            Quarantine