Getting object reference error when Camera.main.ScreenToWorldPoint is used [duplicate]












0
















This question already has an answer here:




  • Camera.main is null when performing raycast

    2 answers




I am getting error




NullReferenceException: Object reference not set to an instance of an
object SinglePoint.Update () (at Assets/Script/SinglePoint.cs:52)




and this is my block of code



     if (Input.GetMouseButtonDown (0)) {

//line 52 where error exists: Vector3
currentPosition=Camera.main.ScreenToWorldPoint(Input.mousePosition);

currentPosition.z=-5.0f;

InstatiateCirclePoint(currentPosition,currentLineRenderer.transform);
}









share|improve this question















marked as duplicate by Programmer unity3d
Users with the  unity3d badge can single-handedly close unity3d questions as duplicates and reopen them as needed.

StackExchange.ready(function() {
if (StackExchange.options.isMobile) return;

$('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');

$hover.hover(
function() {
$hover.showInfoMessage('', {
messageElement: $msg.clone().show(),
transient: false,
position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
dismissable: false,
relativeToBody: true
});
},
function() {
StackExchange.helpers.removeMessages();
}
);
});
});
Nov 21 '18 at 18:15


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.























    0
















    This question already has an answer here:




    • Camera.main is null when performing raycast

      2 answers




    I am getting error




    NullReferenceException: Object reference not set to an instance of an
    object SinglePoint.Update () (at Assets/Script/SinglePoint.cs:52)




    and this is my block of code



         if (Input.GetMouseButtonDown (0)) {

    //line 52 where error exists: Vector3
    currentPosition=Camera.main.ScreenToWorldPoint(Input.mousePosition);

    currentPosition.z=-5.0f;

    InstatiateCirclePoint(currentPosition,currentLineRenderer.transform);
    }









    share|improve this question















    marked as duplicate by Programmer unity3d
    Users with the  unity3d badge can single-handedly close unity3d questions as duplicates and reopen them as needed.

    StackExchange.ready(function() {
    if (StackExchange.options.isMobile) return;

    $('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
    var $hover = $(this).addClass('hover-bound'),
    $msg = $hover.siblings('.dupe-hammer-message');

    $hover.hover(
    function() {
    $hover.showInfoMessage('', {
    messageElement: $msg.clone().show(),
    transient: false,
    position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
    dismissable: false,
    relativeToBody: true
    });
    },
    function() {
    StackExchange.helpers.removeMessages();
    }
    );
    });
    });
    Nov 21 '18 at 18:15


    This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.





















      0












      0








      0









      This question already has an answer here:




      • Camera.main is null when performing raycast

        2 answers




      I am getting error




      NullReferenceException: Object reference not set to an instance of an
      object SinglePoint.Update () (at Assets/Script/SinglePoint.cs:52)




      and this is my block of code



           if (Input.GetMouseButtonDown (0)) {

      //line 52 where error exists: Vector3
      currentPosition=Camera.main.ScreenToWorldPoint(Input.mousePosition);

      currentPosition.z=-5.0f;

      InstatiateCirclePoint(currentPosition,currentLineRenderer.transform);
      }









      share|improve this question

















      This question already has an answer here:




      • Camera.main is null when performing raycast

        2 answers




      I am getting error




      NullReferenceException: Object reference not set to an instance of an
      object SinglePoint.Update () (at Assets/Script/SinglePoint.cs:52)




      and this is my block of code



           if (Input.GetMouseButtonDown (0)) {

      //line 52 where error exists: Vector3
      currentPosition=Camera.main.ScreenToWorldPoint(Input.mousePosition);

      currentPosition.z=-5.0f;

      InstatiateCirclePoint(currentPosition,currentLineRenderer.transform);
      }




      This question already has an answer here:




      • Camera.main is null when performing raycast

        2 answers








      unity3d






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Nov 21 '18 at 18:11









      Programmer

      76.7k1088156




      76.7k1088156










      asked Nov 21 '18 at 17:02









      janicejanice

      215




      215




      marked as duplicate by Programmer unity3d
      Users with the  unity3d badge can single-handedly close unity3d questions as duplicates and reopen them as needed.

      StackExchange.ready(function() {
      if (StackExchange.options.isMobile) return;

      $('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
      var $hover = $(this).addClass('hover-bound'),
      $msg = $hover.siblings('.dupe-hammer-message');

      $hover.hover(
      function() {
      $hover.showInfoMessage('', {
      messageElement: $msg.clone().show(),
      transient: false,
      position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
      dismissable: false,
      relativeToBody: true
      });
      },
      function() {
      StackExchange.helpers.removeMessages();
      }
      );
      });
      });
      Nov 21 '18 at 18:15


      This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.









      marked as duplicate by Programmer unity3d
      Users with the  unity3d badge can single-handedly close unity3d questions as duplicates and reopen them as needed.

      StackExchange.ready(function() {
      if (StackExchange.options.isMobile) return;

      $('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
      var $hover = $(this).addClass('hover-bound'),
      $msg = $hover.siblings('.dupe-hammer-message');

      $hover.hover(
      function() {
      $hover.showInfoMessage('', {
      messageElement: $msg.clone().show(),
      transient: false,
      position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
      dismissable: false,
      relativeToBody: true
      });
      },
      function() {
      StackExchange.helpers.removeMessages();
      }
      );
      });
      });
      Nov 21 '18 at 18:15


      This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.


























          1 Answer
          1






          active

          oldest

          votes


















          0














          If this is indeed the correct line of code, you should confirm that you have a Camera added to your scene and that it has the Tag "MainCamera" attached to it.



          enter image description here






          share|improve this answer






























            1 Answer
            1






            active

            oldest

            votes








            1 Answer
            1






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes









            0














            If this is indeed the correct line of code, you should confirm that you have a Camera added to your scene and that it has the Tag "MainCamera" attached to it.



            enter image description here






            share|improve this answer




























              0














              If this is indeed the correct line of code, you should confirm that you have a Camera added to your scene and that it has the Tag "MainCamera" attached to it.



              enter image description here






              share|improve this answer


























                0












                0








                0







                If this is indeed the correct line of code, you should confirm that you have a Camera added to your scene and that it has the Tag "MainCamera" attached to it.



                enter image description here






                share|improve this answer













                If this is indeed the correct line of code, you should confirm that you have a Camera added to your scene and that it has the Tag "MainCamera" attached to it.



                enter image description here







                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered Nov 21 '18 at 17:12









                Shawn LehnerShawn Lehner

                1,260712




                1,260712















                    Popular posts from this blog

                    If I really need a card on my start hand, how many mulligans make sense? [duplicate]

                    Alcedinidae

                    Can an atomic nucleus contain both particles and antiparticles? [duplicate]